Jump to content

Cannot locate error


Fearpig

Recommended Posts

Hello,
I'm currently working through the PHP SQL tutorial at the address below:

http://webmonkey.wired.com/webmonkey/99/21/index2a.html

but I'm getting stuck on one of the earlier lessons. I've posted my code below (slightly changed from the tutorial). Would someone take a look at it please and see if they spot the problem? When I run the file I get the two following error messages:

[color=red]Notice: Undefined variable: id in D:\Intranet v3\php_telephone_list\Lesson4b.php on line 13

Notice: Undefined variable: PHP_SELF in D:\Intranet v3\php_telephone_list\Lesson4b.php on line 37[/color]

<html>
<head>
</head>
<body>
<?php

$db = mysql_connect("localhost", "root", "password");

mysql_select_db("Telephonelist",$db);
// display individual record

if ($id) {

  $result = mysql_query("SELECT * FROM tbl_telephonenumbers WHERE ID=$id",$db);

  $myrow = mysql_fetch_array($result);

  printf("First name: %s\n<br>", $myrow["First_Name"]);

  printf("Last name: %s\n<br>", $myrow["Last_Name"]);

  printf("Address: %s\n<br>", $myrow["Address_1"]);

  printf("Position: %s\n<br>", $myrow["Role"]);

} else {
    // show employee list

  $result = mysql_query("SELECT * FROM tbl_telephonenumbers",$db);

    if ($myrow = mysql_fetch_array($result)) {
      // display list if there are records to display

      do {

        printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["ID"], $myrow["First_Name"], $myrow["Last_Name"]);

      } while ($myrow = mysql_fetch_array($result));

    } else {
    // no records to display

      echo "Sorry, no records were found!";

    }
}

?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/15703-cannot-locate-error/
Share on other sites

Change $PHP_SELF to $_SERVER['PHP_SELF'] and $id to either $_POST['id'] or $_GET['id']

This is becuase webmonkey did this tutorial with register_globals enabled and you dont. I would advise you carrying on with that tutorial as it is out of date.
Link to comment
https://forums.phpfreaks.com/topic/15703-cannot-locate-error/#findComment-64109
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.