Hi All,
I am trying to write a page that queries a MySQL database to select all students taking a certain degree (the DegreeId is selected from a drop down list box).
However the SQL statement I have is giving me an error.
Can anyone see the error in the statement, and provide me with the right one please? 🙂
The database tables look like this
Table STUDENT
http://www.comp.glam.ac.uk/students/02015072/student.jpg
Table DEGREE
http://www.comp.glam.ac.uk/students/02015072/degree.jpg
Page Code
<?php
Acquire SQL string and output on page
$degree = $_POST['select_degree'];
echo "Your chosen degree was: <b>$degree</b>"."<br>"."<br>"."<b>Results</b>"."<br>"."<br>";
$username = "user_02015072";
$password = "password";
$hostname = "localhost";
$sql_query = "SELECT DISTINCT s.* FROM student s INNER JOIN degree USING(DegreeId) WHERE DegreeId = '$degree'";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("db_02015072",$dbh)
or die("Could not select first_test");
$result = mysql_query("$sql_query");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
print "ID: ".$row{'StudentId'}."<br>"." First Name: ".$row{'Stud_FName'}."<br>"." Last Name: ".$row{'Stud_SName'}."<br>"."<br>";
}
mysql_close($dbh);
?>
Many Thanks,
dai.hop