I'm trying to send a query to my database based on a username through use of the following method:
$user = " ";
$password = " ";
$hostname = "localhost";
$db = " ";
$conn = mysql_connect($hostname, $user, $password)
or die("<p>Failed to Connect to Database:</p>" . mysql_error());
extract($_POST);
if($u == "tslack")
{
$sql_client = "SELECT * FROM formdata WHERE Instructor = 'Tom Slack' AND Semester = '$SlackSemester' AND Year = '$SlackYear' ";
}
else if($u == "dhoch")
{
$sql_client = "SELECT FROM formdata WHERE Instructor = 'Deborah Hochstein' AND Semester = '$DebSemester' AND Year = '$DebYear' ";
}
else if($u == "aprofitt")
{
$sql_client = "SELECT FROM formdata WHERE Instructor = 'Alan Profitt' AND Semester = '$AlanSemester' AND Year = '$AlanYear' ";
}
$info = mysql_db_query($db, $sql_client)
or die("Invalid query: " . $sql_client . "<p>" . mysql_error());
while($myrow=mysql_fetch_row($info))
{
echo "$sql_client<BR>";
}
For instance, if I login as tslack I get the query statement instead of the data in the database. Tslack has two records in the database so when I select his name it shows:
"SELECT FROM formdata WHERE Instructor = 'Tom Slack' AND Semester = '$SlackSemester' AND Year = '$SlackYear' ";
"SELECT FROM formdata WHERE Instructor = 'Tom Slack' AND Semester = '$SlackSemester' AND Year = '$SlackYear' ";
....instead of the data. In other words, its showing the query I sent to the database instead of actually running the query and showing the data. What am I doing wrong?
Thanks in advance,
EJ