warning undefined variable ONLY on NT box?

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

Post Reply
netwench
Forum Newbie
Posts: 4
Joined: Tue Jul 16, 2002 11:38 am

warning undefined variable ONLY on NT box?

Post by netwench »

hi all, very newbie here.
i'm using a webmonkey tutorial on php with mysql. i can connect, create, edit, etc just fine. my problem is ONLY on an nt 4.0 iis 4 box do i get the error message
Warning: Undefined variable: submit in D:\Inetpub\wwwroot\endscript.php on line 6

Warning: Undefined variable: delete in D:\Inetpub\wwwroot\endscript.php on line 18

Warning: Undefined variable: id in D:\Inetpub\wwwroot\endscript.php on line 25

when using this script (below). i am running the same setup just fine on my host's linux box. no errors at all.
unfortunately, i am the admin on the nt box.
the script actually WORKS on BOTH, but i only get this error on the nt box. (up to the point where it's trying to use the undefined variables) i have heard somewhere that maybe there is some sort of error reporting thing that perhaps i can turn off? or am i barking up the wrong tree?

please help. linux box is running php 4.0.6 and nt is running php 4.1.1.


<html>
<body>
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("play_mydb",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($id) {
$sql = "UPDATE employees SET

first='$first',last='$last',address='$address',position='$position'
WHERE id=$id";
} else {
$sql = "INSERT INTO employees (first,last,address,position) VALUES
('$first','$last','$address','$position')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM employees WHERE id=$id";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$id) {
// print the list if there is not editing
$result = mysql_query("SELECT * FROM employees",$db);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"],

$myrow["first"],
$myrow["last"]);
printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF,
$myrow["id"]);
}
}
?>
<P>
<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>
<P>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($id) {
// editing so select a record
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$first = $myrow["first"];
$last = $myrow["last"];
$address = $myrow["address"];
$position = $myrow["position"];
// print the id for editing
?>
<input type=hidden name="id" value="<?php echo $id ?>">
<?php
}
?>
First name:<input type="Text" name="first" value="<?php echo $first

?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last

?>"><br>
Address:<input type="Text" name="address" value="<?php echo $address

?>"><br>
Position:<input type="Text" name="position" value="<?php echo $position

?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>

thanks!!!
leann
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Error reporting is at it's highest level on the box with the warnings. You can turn that down, it won't get rid of the error but you won't get a notice either or start using isset():

Code: Select all

if (isset($HTTP_POST_VARS&#1111;'submit'])) &#123;
Mac
netwench
Forum Newbie
Posts: 4
Joined: Tue Jul 16, 2002 11:38 am

Post by netwench »

thanks!!! again, just reading thru posts i figured there had to be some switch i could change- would you mind pointing me in the direction of where to learn to change this ? and which one? i have been looking for it, but all the instructions i've seen are for unix and i still haven't discovered which name it is.

use isset? ok, i'll have to look that up (again, very newbie here). but why would NOT using that work on *nix and not nt? i'm just looking for some logic to know when i should or should not use it....

i really appreciate your help!

leann
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's because of the error reporting (have a look in your php.ini file to adjust this). Basically the error is occuring on the *nix box but the error reporting is set lower so a notice is not displayed.

The php.ini file should be in the WINNT directory on windows NT.

Mac
netwench
Forum Newbie
Posts: 4
Joined: Tue Jul 16, 2002 11:38 am

Post by netwench »

YOU ROCK!
it works great now!!! i just have e_error and e_parse

i'll have to look into isset more..... got any great examples?


thanks SO much for your help!!

leann
Post Reply