I'm trying to access a variable from another form but cant seem to get it to work can any one see my problem?
Main Menu
Result PageCode:<? // script to display all the Degrees in the Degree table // connection information $hostName = "localhost"; $userName = "root"; $password = "12345"; $dbName = "SOC_DBtest"; // make connection to database mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Select all the fields in all the records of the Employees table $query = "SELECT * FROM tbl_degree"; $result = mysql_query($query); // Determine the number of employees $number = mysql_numrows($result); // Create drop-down menu of degree names print "View students enroled on a specified degree scheme:<p> <form action=\"StudentDegree.php\" method=\"post\"> <select name=\"DegreeId\"> <option value=\"\">Select a degree scheme</option>"; for ($i=0; $i<$number; $i++) { $DegreeId = mysql_result($result,$i,"DegreeId"); $Degree_Name = mysql_result($result,$i,"Degree_Name"); print "<option value=\"$DegreeId\">$Degree_Name</option>"; } print "</select><input type=\"submit\" value=\"submit\" name=\"submit\"></form>"; // Close the database connection mysql_close(); ?>
it prings up an error with my SQL query, i think it's the WHERE clause, where the $DegreeID isn't being accessed from the main menuCode:<? // script to display who is on a specific degree // connection information $hostName = "localhost"; $userName = "root"; $password = "12345"; $dbName = "SOC_DBtest"; // make connection to database mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName"); mysql_select_db($dbName) or die( "Unable to select database $dbName"); // Select the fields from the appropriate tables $query = "SELECT tbl_student.Student_Id, tbl_student.Student_FName, tbl_student.Student_SName, tbl_degree.Degree_Name FROM tbl_degree INNER JOIN tbl_student ON tbl_degree.Degree_Id = tbl_student.Degree_Id WHERE ((tbl_student.Degree_Id = $DegreeId))"; $result = mysql_query($query); // Determine the number of records returned $number = mysql_numrows($result); // Print the relevant information print "There are $number student(s) studying this Degree:<p>"; for($i=0; $i<$number; $i++) { $studentId = mysql_result($result, $i, "student_Id"); $stud_FName = mysql_result($result, $i, "Student_FName"); $stud_SName = mysql_result($result,$i,"Student_SName"); $stud_Degree = mysql_result($result,$i,"Degree_Name"); print "$studentId - $stud_FName $stud_SName - $stud_Degree<br>"; } // Close the database connection mysql_close(); ?>




Reply With Quote