php code in iis/apache
Moderator: General Moderators
php code in iis/apache
im reading a book about php and follow the example. the example was passing of form variable to another form. i ran it and got errors. the variable were not parsed - undefined error... the same code, i tried it in apache and it works well. what could be the reason for this? some example w/c doesn't involve passing of variable from a page to another works well too. can somebody help me. thanks in advance!

Im using Wrox - Beginning PHP4. There is no error in the html and php. Im just curious about the error im receiving when im trying it on iis while in apache it works fine.
error in iis:
Notice: Undefined variable: Salary in c:\inetpub\wwwroot\learningphp\Loan.php on line 9
while in apache: no problem at all. I get correct result.
error in iis:
Notice: Undefined variable: Salary in c:\inetpub\wwwroot\learningphp\Loan.php on line 9
while in apache: no problem at all. I get correct result.
Oops, there additional prob. I already changed the register_globals=on and yet some examples in the book generates that same "notice... blah blah..." What should i do about it?
Here's d code:
=============car.htm==============
<HTML>
<HEAD></HEAD>
<BODY>
<B>Namllu Car Hire Company</B>
<FORM METHOD=POST ACTION="car.php">
First Name:
<INPUT NAME="FirstName" TYPE="Text">
Last Name:
<INPUT NAME="LastName" TYPE="Text">
Age:
<INPUT NAME="Age" TYPE="Text"SIZE="3">
<BR>
<BR>
Address:
<TEXTAREA NAME="Address" ROWS=4 COLS=40>
</TEXTAREA>
<BR>
<BR>
Do you hold a current driving license?
<INPUT NAME="License" TYPE="Checkbox">
<BR>
<BR>
<INPUT TYPE=SUBMIT VALUE="Click here to Submit application">
</FORM>
</BODY>
</HTML>
========================================
car.php
========================================
<HTML>
<HEAD></HEAD>
<BODY>
<B>Namllu Car Hire Company</B>
<?php
if ($Age>20 AND $License=="on") echo ("Your car hire has been accepted.");
if ($Age<21 OR $License=="") echo ("Unfortunately we cannot hire a car to you.");
?>
</BODY>
</HTML>
========================================
If i enter age > 20 and checkbox is unchecked - same error like before the - Notice: Undefined variable: License in c:\inetpub\wwwroot\learningphp\car.php on line 6
im using iis5.1
thanks again!
Here's d code:
=============car.htm==============
<HTML>
<HEAD></HEAD>
<BODY>
<B>Namllu Car Hire Company</B>
<FORM METHOD=POST ACTION="car.php">
First Name:
<INPUT NAME="FirstName" TYPE="Text">
Last Name:
<INPUT NAME="LastName" TYPE="Text">
Age:
<INPUT NAME="Age" TYPE="Text"SIZE="3">
<BR>
<BR>
Address:
<TEXTAREA NAME="Address" ROWS=4 COLS=40>
</TEXTAREA>
<BR>
<BR>
Do you hold a current driving license?
<INPUT NAME="License" TYPE="Checkbox">
<BR>
<BR>
<INPUT TYPE=SUBMIT VALUE="Click here to Submit application">
</FORM>
</BODY>
</HTML>
========================================
car.php
========================================
<HTML>
<HEAD></HEAD>
<BODY>
<B>Namllu Car Hire Company</B>
<?php
if ($Age>20 AND $License=="on") echo ("Your car hire has been accepted.");
if ($Age<21 OR $License=="") echo ("Unfortunately we cannot hire a car to you.");
?>
</BODY>
</HTML>
========================================
If i enter age > 20 and checkbox is unchecked - same error like before the - Notice: Undefined variable: License in c:\inetpub\wwwroot\learningphp\car.php on line 6
im using iis5.1
thanks again!
- mrvanjohnson
- Forum Contributor
- Posts: 137
- Joined: Wed May 28, 2003 11:38 am
- Location: San Diego, CA
I've noticed working with IIS and PHP, it does a lot of chirping when you don't define every variable your using in the code. You might want to just try adding the following to the top of your code for car.php
This would be one way you would handle forms with Globals off. If you are learning how to code, this is a better way to learn because it's what you are going to run into more likely than not. It's a good coding standard.
Fortunately/Unfortunately PHP is in a major maturity stage right now where it's doing a lot of growing very quick. Good because it is just getting better and better, bad because things like books are being out dated before the hit the shelf. Books are good for general understanding of PHP and it's functions. But actually getting on line and finding current tutorials and coding yourself is still the best way to learn PHP.
Code: Select all
<?php
$License = $_POST['License'];
?>Fortunately/Unfortunately PHP is in a major maturity stage right now where it's doing a lot of growing very quick. Good because it is just getting better and better, bad because things like books are being out dated before the hit the shelf. Books are good for general understanding of PHP and it's functions. But actually getting on line and finding current tutorials and coding yourself is still the best way to learn PHP.
I tried this:
=============================================
test.htm
<form action="test.php" method="post">
Test: <input type="checkbox" name="test">
<br>
<input type="Submit" value="Parse" />
</form>
=============================================
test.php
<?php echo "$test" ?>
=============================================
When I check the checkbox and press the parse button it shows "on". But when i uncheck the checkbox an error shows up.
Error:
Notice: Undefined variable: test in c:\inetpub\wwwroot\learningphp\test.php on line 7
I tried your suggestion in test.php
first:
<?php $License = $_POST['License']; ?>
<?php echo "$test" ?>
second:
<?php $License = $_POST['License']; echo "$test" ?>
And I still get the error + new:
checkbox=check
Notice: Undefined index: License in c:\inetpub\wwwroot\learningphp\test.php on line 7
on <- answer still shows up
checkbox=uncheck
Notice: Undefined index: License in c:\inetpub\wwwroot\learningphp\test.php on line 7
Notice: Undefined variable: test in c:\inetpub\wwwroot\learningphp\test.php on line 7
Btw, Im using php-4.3.4-Win32
=============================================
test.htm
<form action="test.php" method="post">
Test: <input type="checkbox" name="test">
<br>
<input type="Submit" value="Parse" />
</form>
=============================================
test.php
<?php echo "$test" ?>
=============================================
When I check the checkbox and press the parse button it shows "on". But when i uncheck the checkbox an error shows up.
Error:
Notice: Undefined variable: test in c:\inetpub\wwwroot\learningphp\test.php on line 7
I tried your suggestion in test.php
first:
<?php $License = $_POST['License']; ?>
<?php echo "$test" ?>
second:
<?php $License = $_POST['License']; echo "$test" ?>
And I still get the error + new:
checkbox=check
Notice: Undefined index: License in c:\inetpub\wwwroot\learningphp\test.php on line 7
on <- answer still shows up
checkbox=uncheck
Notice: Undefined index: License in c:\inetpub\wwwroot\learningphp\test.php on line 7
Notice: Undefined variable: test in c:\inetpub\wwwroot\learningphp\test.php on line 7
Btw, Im using php-4.3.4-Win32
When you uncheck the checkbox and then click submit, browser just don't send the checkbox value as a part of the request. So on the server side corresponding var is undefined. you need to test, if it's defined:
or just suppress the notice:
Code: Select all
if(isset($test)) echo $test;Code: Select all
echo @$test;I have enable the "error_reporting" in php.ini and restart web server and the server still display the Notices, why? What is gone wrong?Bech100 wrote:You can define all your variables (e.g. $i="") before you use them, or you can change the error_reporting setting in php.ini so that it doesn't report notices:
error_reporting = E_ALL & ~E_NOTICE
Also have a look at the display_errors and log_errors settings in the php.ini.
Mark