Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2005, 10:00 AM
Registered User
 
Join Date: Apr 2005
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
[email protected]
 
Old April 23rd, 2005, 10:22 AM
Authorized User
 
Join Date: Jan 2005
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
 
Old April 23rd, 2005, 11:56 AM
Registered User
 
Join Date: Apr 2005
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
[email protected]
 
Old April 23rd, 2005, 12:39 PM
Registered User
 
Join Date: Apr 2005
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
[email protected]
 
Old April 24th, 2005, 06:33 AM
Friend of Wrox
 
Join Date: Mar 2004
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






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





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