Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.