Hi everyone
I am using php and mysql for my degree project. The problem is that I am allowing people to search for a student by typing in the name and then the students details, if found, are displayed in a table.
My data is not being displayed and I can't understand why. I have three files: first one is profile.php which contains the search form, then processlogin.php and then student.php.
On submitting the search, the student.php does get displayed minus the database results, so am I right to assume that the processlogin.php file is ok?
If anyone could please help, it would be greatly appreciated. Thanks
Code: profile.php
<form method=post action="processlogin.php">
<table cellspacing=0 cellpadding=4 style='border: 1px solid black; font-size: 9pt'>
<tr><td style='background-color: rgb(236,219,185)'>
<table style='font-size: 9pt'>
<tr>
<td valign=middle>Student's First Name:</td>
<td valign=middle><input type=text name=name></td>
<td valign=middle>(eg. Asfan)</td>
</tr>
</table>
</td></tr>
</table>
<p>
<input type=submit value="Search">
</form>
Code: processlogin.php
$post = $HTTP_POST_VARS;
if ($post) {
$name = $post["name"];
}
$conn = mysql_connect("") or die ("Could not connect to MySQL");
mysql_select_db("");
$query = "SELECT StudentID FROM students where Forename ='$name'";
$result = mysql_query($query) or die("Query failed");
if ($result)
{
setcookie("student", $name);
header("Location: student.php");
}
else
{
echo "Student details not found";
}
else {
echo "Error in filling form";
}
Code: student.php
$conn = mysql_connect("") or die ("Could not connect to MySQL");
mysql_select_db("");
if ($student){
// query the DB
$sql = "SELECT * FROM students WHERE StudentID='$student'";
$result = mysql_query($sql) or die("Query failed");
$line = mysql_fetch_array($result);
}
?>
<!-- #EndEditable -->
<table width="80%" border="1">
<tr>
<td width="22%">
<p><b>Name</b></p>
</td>
<td colspan="3"><!-- #BeginEditable "Name" --><?=$line["Forename"]?> <?=$line["Surname"]?><!-- #EndEditable --></td>
</tr>
<tr>
<td width="22%">
<p><b>PhD title</b></p>
</td> ---and so on