php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7985 All PHP 3 scripts have "Undefined Variable" Warnings
Submitted: 2000-11-26 21:24 UTC Modified: 2000-11-26 21:36 UTC
From: richlacroix at home dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0.3pl1 OS: Win 98 SE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: richlacroix at home dot com
New email:
PHP Version: OS:

 

 [2000-11-26 21:24 UTC] richlacroix at home dot com
Running the PHP tutorial on the latest Apache build with the latest MySQL available (all for win 32k) the example scripts that were written for PHPv3 always come back with Warning: Undefined variable, i.e. 
Warning: Undefined variable: submit in d:\program files\apache group\apache\htdocs\mysqltest.php on line 21

Warning: Undefined variable: delete in d:\program files\apache group\apache\htdocs\mysqltest.php on line 41

Warning: Undefined variable: id in d:\program files\apache group\apache\htdocs\mysqltest.php on line 55
 from the following script (taken from the tutorial located at:
http://hotwired.lycos.com/webmonkey/99/21/index2a.html )

Script:
<html>



<body>

<?php



$db = mysql_connect("localhost", "Web User");

mysql_select_db("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>

I'm new to PHP, but not development, I've checked the script against every bit of documentation I could find - spending an entire day doing so, but I can't understand why this is happening - according to everything I've seen so far, this should not be happening.
Please advise.
Thanks
Richard
P.S. Simple scripts work fine, as long as I don't try anything like a $submit, $delete, and so on from a form. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-26 21:36 UTC] rasmus@php.net
Those are very valid warnings.  You get them in PHP 3 as well if you set your error_reporting level high enough.  If you don't want to see these warnings change your error_reporting level in your php.ini file.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 21:01:29 2024 UTC