Jump to content


Photo

Cannot locate error


  • Please log in to reply
2 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 26 July 2006 - 03:33 PM

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

http://webmonkey.wir...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:

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


<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>


"Whats wrong with the cat?" - Mrs Schrödinger

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 03:38 PM

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.

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 27 July 2006 - 10:58 AM

Thank you Wildteen....

only just started with PHP and I was scratching my head. Do you know of any good up-to-date tutorials?
"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users