I am currently doing a project a uni and cant get my hyperlinks relating to my sql database to pull info from one page to another. I am very fustrated with this and if anyone can see the problem i would be glad of a tip. The worst thing is that the example was done by the lecturer. ive changed the user and password
I cant figue out how the student no is passed accross..
<html>
<body>
<?php
/
This is an example showing how to list records as hyperlink and associated key data/variables.
/
// Connect to server
// Replace username and password by your details
$db = @mysql_connect("localhost","user","password");
if (!$db)
{
do_error("Could not connect to the server");
}
// Connect to the database
// Note that your database will be called username
@mysql_select_db("students",$db)or do_error("Could not connect to the database");
// Run the search query
$result = mysql_query("SELECT * FROM students ORDER BY student_no",$db);
// Check that something was found
$rows=@mysql_num_rows($result);
// Output the search results
if(!$rows)
{
do_error("No results found");
}
else
{
echo "<table border=3 cellspacing=1 cellpadding=1
align=center bgcolor=lightgreen>\n";
echo "<caption><h2><font color=blue>Students</font></h2></caption>\n";
echo "<tr><th>Student No</th><th>Name</th></tr>\n";
while ($myrow = mysql_fetch_array($result))
{
printf("<tr><td>%s %s</td>\n",
$myrow["firstname"],$myrow["secondname"]);
printf("<td><a href=\"mysql_Ex2_7b.php?studentid=%s\">%s</a></td></tr>\n",
$myrow["student_no"],$myrow["student_no"]);
}
echo "</table>\n";
}
echo "<br><center>Click on the student number to update the entry</center><br>\n";
// Close the connection - not really necessary
mysql_close($db) or do_error("Could not close connection");
function do_error($error)
{
echo $error;
die;
}
?>
PAGE 2 is.......
</html>
<html>
<head><title>Modify Student Form</title></head>
<body>
<h2 align=center><font color=blue>Modify a Student Record</font> </h2><p>
Enter the student details below:<br>
<form action="mysql_Ex2_7c.php" method="POST">
<?php
// Connect to server
// Replace username and password by your details
$db = @mysql_connect("localhost","user","pass");
if (!$db)
{
do_error("Could not connect to the server");
}
// Connect to the database
// Note that your database will be called username
@mysql_select_db("students",$db)or do_error("Could not connect to the database");
$result = mysql_query("SELECT * FROM students WHERE student_no=$studentid",$db);
// Check that something was found
$rows=@mysql_num_rows($result);
// Output the search results
if(!$rows)
{
do_error("No results found");
}
else
{
// Fetch the selected record from the database
$myrow = mysql_fetch_array($result);
echo "<pre>\n";
printf("Student Number: %s<br>", $studentid);
printf("<input type=\"hidden\" name=\"student_no\" value=\"%s\" size=5><br>",$myrow["student_no"]);
printf("First Name: <input type=\"text\" name=\"firstname\" value=\"%s\" size=20><br>",$myrow["firstname"]);
printf("Second Name: <input type=\"text\" name=\"secondname\" value=\"%s\" size=20><p>",$myrow["secondname"]);
echo "</pre>";
}
mysql_close($db) or do_error("Could not close connection");
function do_error($error)
{
echo $error;
die;
}
?>
<input type="submit" value="Modify">
<input type="reset" value="Reset">
</form>