php code in iis/apache

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

php code in iis/apache

Post by Flash05 »

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! ;) :( :D
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

The book might be outdatted and does not follow to the newer syntax requirements.

Post the code, and someone can point out the errors.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Take a look at this too:

viewtopic.php?t=511

-Nay
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

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
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

Tnx Nay for the link. Problem solved! :D :D :D
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Sure 8). np, anyone's better than the guy who's seen in porn 8O...

-Nay
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

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!
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

did you do what i said in my post, that is where your problem stems from!

Mark
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

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

Code: Select all

<?php
$License = $_POST['License'];
?>
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.
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

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:

Code: Select all

if(isset($test)) echo $test;
or just suppress the notice:

Code: Select all

echo @$test;
Flash05
Forum Commoner
Posts: 25
Joined: Thu Dec 18, 2003 3:16 am

Post by Flash05 »

Tnx man! Btw, how do i use this:
<?php $test = $_POST['test']; echo "$test" ?> Do i have to declare another block of <? ?> or just include it in the current?

Tnx again for the helP! :D :D :D
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Make a new page and test it out. :wink:
Eric123
Forum Newbie
Posts: 5
Joined: Fri Dec 19, 2003 12:58 am

Post by Eric123 »

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
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?
Post Reply