As Redscouse says, $_GET[‘id’] is NULL when the page first loads if you don’t have a value in the URL parameter id=, for example: Somepage.php, rather than Somepage.php?id=5.
So you need to check that $_GET[‘id’] contains something before executing the subsequent script.
For example:
[php]<?php
if (isset($_GET[“id”])){
// Connect to database server
mysql_connect(“localhost”, “root”, “”) or die (mysql_error ());
// Select database
mysql_select_db("lms") or die(mysql_error());
// (Line 17) Get data from the database depending on the value of the id in the URL
$strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"];
$rs = mysql_query($strSQL);
// (Line 21) Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
// Write the data of the person
echo "<dt>Name:</dt><dd>" . $row["name"] . "</dd>";
echo "<dt>Username:</dt><dd>" . $row["username"] . "</dd>";
echo "<dt>Rollno:</dt><dd>" . $row["rollno"] . "</dd>";
}
}
else{
echo “No ID supplied”;
}
?>
[/php]
I would also check that the value of id is numeric and that that the query returns a result before trying to loop through it, something like this:
[php]
if (isset($_GET[“id”])){
$intID=$_GET[“id”];
}
else{$intID=“x”;
}
if (is_numeric($intBID)==true){
// Connect to database server
mysql_connect(“localhost”, “root”, “”) or die (mysql_error ());
// Select database
mysql_select_db("lms") or die(mysql_error());
// (Line 17) Get data from the database depending on the value of the id in the URL
$strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"];
$rs = mysql_query($strSQL);
if (mysql_num_rows($rs)>0){
// (Line 21) Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
// Write the data of the person
echo "<dt>Name:</dt><dd>" . $row["name"] . "</dd>";
echo "<dt>Username:</dt><dd>" . $row["username"] . "</dd>";
echo "<dt>Rollno:</dt><dd>" . $row["rollno"] . "</dd>";
}
}
}
else{
echo "No ID supplied, or ID not valid";
}
}
[/php]
That way, if the URL parameter is empty or has been tampered with it give a nice error message rather than a PHP error message.
While we’re on the subject, you shouldn’t really retrieve User information with $_GET because it’s visible in the browser address bar, so it can be tampered with to retrieve a different user’s information. Use $_POST instead.