if (isset($_GET['id'])) {$id = $_GET['id'];} $result = mysql_query("SELECT * FROM students WHERE id='$id'",$db); $myrow = mysql_fetch_array($result); 

It turns out that the variable id undefined.

Notice: Undefined index: id

Maybe because register_globals Off ?

There is a page with a list:

  <?php $result = mysql_query("SELECT id,name FROM students",$db); $myrow = mysql_fetch_array($result); do { printf ("<p><a href='students_view.php?=%s'>%s</a><br></p>",$myrow["id"],$myrow["name"]); } while ($myrow = mysql_fetch_array($result)); ?> 

Here is a generator. code:

 <a href="students_view.php?=1">Руслан</a> 
  • added sgen. html code of that line - bakusite

4 answers 4

1) id can be $_GET['id'] if $_GET['id'] is not passed.
2) register_globals is a directive that transfers the contents of $_GET and $_POST to the global scope, and in this case it does not matter.

You don’t rightly call the script, do it like this: students_view.php? Id = 2
Or (if the id is somehow transmitted) change $_GET to $_POST or $_REQUEST

It is generally worth rewriting something like this:

 if ( !isset($_GET['id']) || ( ( $id = (int)$_GET['id'] ) < 1 ) ) die("Error of ID"); $result = mysql_query("SELECT * FROM students WHERE id='$id'",$db); $myrow = mysql_fetch_array($result); 

Here is the error:

 <p><a href='students_view.php?=1'>Алик</a><br></p> 

But you must:

 <p><a href='students_view.php?id=1'>Алик</a><br></p> 

Those. change php:

 printf ("<p><a href='students_view.php?id=%s'>%s</a><br></p>",$myrow["id"],$myrow["name"]); 
  • 1) Well, he does not want to transmit the id value of $ _GET ['id'] 2) thanks for the info 3) the table is specified - bakusite
  • added to the question code - bakusite
  • Added html code of a page with a list - bakusite
  • Thank you so much !!! - bakusite

$id = (int) $_GET['id']; - if $_GET['id']; not set, id will be 0. Then you can just check if($id){...} .

    Try this

      $ result = mysql_query ("SELECT * FROM name_table WHERE id = '$ id'", $ db); 
    First of all, secondly, you probably didn’t convey it correctly either. At the end of this code put

    var_dump ($ _ GET);

    And write what brought

    • Notice: Undefined variable: id in students_view.php on line 4 array (0) {} That's what comes out now - bakusite
    • This means that you don’t pass over any variable to the GET method - iproger
     result = mysql_query("SELECT * WHERE id='$idus'",$db); 

    Here you are mistaken or correctly written? $ idus or just $ id?

    • That's right, $ id, and it still doesn't work - bakusite