Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 23rd, 2005, 10:00 AM
Registered User
 
Join Date: Apr 2005
Location: Clayton, NC, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't pass variables to form for validation!

Hello Everyone!

I'm pretty new to PHP and web design in general. I've been working through the "Beginning PHP4" book.

I'm trying to make a form for my company website to conduct a survey. I'm attempting to validate the form, but my if statements in my php page don't seem to be picking up the variables from my form on my html page!

I used a <form method=get action="http://www.mypage.com/myfile.php4"> tag in my html page. The pages seem to be "linking up" server side. No matter what I do, though, I can't evaluate the string values in my radio button variables.

Here are some examples from my code:

HTML page:

<input name="FB" type="radio" value="Yes">
Yes
<br />
<input name="FB" type="radio" value="No">
No

PHP page:

if($FB!="Yes" AND $FB!="No")
{
    echo "You have not answered Question 1. Please click the back button in your browser to try again.";
    exit;
}

Can anyone tell me why this isn't working?

Thanks!
gnilly


Josh Gilliam
gnilly@hotmail.com
Reply With Quote
  #2 (permalink)  
Old April 23rd, 2005, 10:22 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

first change the method to "POST"
in your PHP page, did you do this:

$FB = $_GET['FB'];

before you tried to use $FB? because if you haven't declared it, it has no clue where $FB came from.


----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq
Reply With Quote
  #3 (permalink)  
Old April 23rd, 2005, 11:56 AM
Registered User
 
Join Date: Apr 2005
Location: Clayton, NC, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I tried that, and I still can't make it work.

When I work through the examples in the "Begininning PHP4" book I have, I don't have to use the $_GET[]. PHP assigns a variable just from the form sending in the "name" of each <input>. Why won't that work here?

It seems I CAN make the validation work, if I enter numbers instead of strings for the names on the form. Please help!! I'm confused...



Josh Gilliam
gnilly@hotmail.com
Reply With Quote
  #4 (permalink)  
Old April 23rd, 2005, 12:39 PM
Registered User
 
Join Date: Apr 2005
Location: Clayton, NC, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah! I made it work!!

I replaced my former if statement with:

if ($HTTP_POST_VARS["FB"]!="Yes" AND $HTTP_POST_VARS["FB"]!="No")

This pulled in the variables for me!

I think the problem is that my work e-mail server has an older version of PHP on it, and my personal site where I've been working on the examples from the book has a new version. The new version has the variables automatically created from the html form, but the old version doesn't seem to do it that way.

Thanks for your help, Gotaka4!


Josh Gilliam
gnilly@hotmail.com
Reply With Quote
  #5 (permalink)  
Old April 24th, 2005, 06:33 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

But, generally, on remote server, register_globals is set off, and this can't be made on using ini_set() [ can only be done per directory basis by setting mod_php4.c on in .htaccess ]

Hence, $_ENV, $_GET[], $_POST[], $_COOKIE[], $_SERVER[] is better2write than HTTP_VARS ( $_REQUEST[] works for querystrings )

Recently, I've2transfer an entire project from IIS/PHP to Apache/PHP, because of HTTP_VARS

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Variables obrienkev C# 2005 1 July 18th, 2008 03:58 AM
How do I Pass Session Variables cdanczak Classic ASP Professional 0 November 27th, 2007 10:42 AM
Is it better to pass variables to a function? stephen_c_ Beginning PHP 3 November 4th, 2005 05:07 AM
How Do I Pass 2 Variables in Javascript Lucy Javascript 2 December 13th, 2003 11:25 AM



All times are GMT -4. The time now is 09:09 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.