TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

PHP: Undefined Variable errors.

Page: 1 Reply
Mar 8th 2004#144694 Report
Member since: Jul 5th 2003
Posts: 80
I'm having a bit of a problem.

Here is the scenario: I have two pages. The first one is an HTML page containing a form with several text input fields and a checkbox (our focus here). The form submits the info to the second page, which is a .php page. Now, the php script is written so that if the checkbox is checked, thus returning a value of "on" it will display one line of text, and if the checkbox was unchecked (which I assumed returned no value) then it would display a different line. Pretty basic, but I'm learning.

The problem is that when the checkbox is unchecked, I get a variable undefined error. The tags for the form and checkbox are


form method=post action="car.php">

and

input name="License" type="checkbox">

(*Edit - removed the opening tags)

The php script is:


if ($License=="on" AND $Age>20) echo "Your car hire has been accepted.";
if ($License=="" OR $Age<21) echo "Your car hire has not been accepted.";


This is following the guidelines of a PHP book, so I just went ahead and used their text. Any help would be appreciated, as according to the book it should work.
Reply with Quote Reply
Mar 8th 2004#144699 Report
Member since: May 22nd 2003
Posts: 315
you need to use $_POST['variableName'] to get the data from a Form... unless you have globals on...

for example:

input type="text" name="text1">


to get that ont he next page you'd use
$text1 = $_POST['text1'];



assuming that the form method was 'opst'
Reply with Quote Reply
Mar 8th 2004#144703 Report
Member since: Nov 26th 2001
Posts: 2586
also anytime you allow a form variable to not be set, check that it is indeed not set by using [php]isset()[/php]

So an example in your case:
[php]
if ( isset($_POST['some_checkbox_var']) ) {
mmmm doughnuts.... (execute some code.)
}
[/php]

of course you can also use the not set version in some cases: [php] if ( !isset($someVar) ) { ..... [/php]

If it's not set it will just ignore it.
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum