I have a database set up which assigns a school, and its pertinent information, to a specific id for "calling" purposes. However, I am having a little trouble getting this stuff to come together. The error message that I receive when I click the "go" button is that there is an "Unknown column '$id' in 'where clause' " There definitely is the id column in the database, so I thought defining the variable was the problem, but looking around on some sites, my code seems to be ok. This is very frustrating, and I was wondering if someone could possibly chime in with any help that they could. Thanks in advance. My code is below:
HTML Code:
<form id="form" method="get" action="schoolphp.php">
<select name="id" >
<option value="1">School #1</option>
<option value="2">School #2</option>
<input type="submit" value="Go" />
PHP Code:
<?php //Connect To Database $hostname='x.x.com'; $username='uname'; $password='pass'; $dbname='dbname'; $usertable=school;
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); // Retrieve all the data from the "school" table
$id=$_GET['id'];
$result = mysql_query('SELECT * FROM school WHERE id=$id') or die(mysql_error());
// store the record of the "school" table into $row $row = mysql_fetch_array( $result ); // Print out the contents of the entry
echo "Name: ".$row['school']; echo " GPA: ".$row['gpa'];
?>
|