Jump to content

how to fix "where clause is ambiguous" error!!


mtvaran

Recommended Posts

hi guys how to fix this error. i have this query

$sql = "
    SELECT take.StudentID
          ,student.StudentName
          ,take.CourseID
          ,course.CourseName
    FROM take
        ,student
        ,course
    WHERE take.StudentID = student.StudentID
    AND take.CourseID = course.CourseID
    AND StudentID LIKE '$_POST[sid]%'
    ORDER BY StudentID ASC
";

$result = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error(), E_USER_ERROR);

 

 

 

error msg: Fatal error: MySQL Error: Column 'StudentID' in where clause is ambiguous in C:\wamp\www\dis_take.php on line 98

 

this is my full query for searching data from multiple table. still i could not get any result. could anyone check please where am i made mistake?

<?php  

	$con = mysql_connect("localhost","root","");
if (!$con)
  	{
  	die('Could not connect: ' . mysql_error());
  	}

mysql_select_db("uni", $con);

$sql = "
    SELECT take.StudentID
          ,student.StudentName
          ,take.CourseID
          ,course.CourseName
    FROM take
        ,student
        ,course
    WHERE take.StudentID = student.StudentID
    AND take.CourseID = course.CourseID
    AND take.StudentID LIKE '$_POST[sid]%'
    ORDER BY take.StudentID ASC
";

$result = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error(), E_USER_ERROR);

echo"<br>";

echo "<center><table width=700 border=1>";
echo "<tr><th>StudentID</th><th>StudentName</th><th>CourseID</th><th>CourseName</th></tr>";

while($row = mysql_fetch_array ($result))
echo mysql_error();
{

echo "<tr><td>";
echo $row['StudentID'];
echo "</td><td>";
echo $row['StudentName'];
echo "</td><td>";
echo $row['CourseID'];
echo "</td><td>";
echo $row['CourseName'];
echo "</td></tr>";

}

echo "</table>";

mysql_close($con); 
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.