mtvaran Posted December 2, 2010 Share Posted December 2, 2010 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 Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/ Share on other sites More sharing options...
kenrbnsn Posted December 2, 2010 Share Posted December 2, 2010 Which StudentID do you want to use. You're referencing 2 in the query. Ken Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142335 Share on other sites More sharing options...
mtvaran Posted December 2, 2010 Author Share Posted December 2, 2010 i need to use the StudentID from take table Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142345 Share on other sites More sharing options...
kenrbnsn Posted December 2, 2010 Share Posted December 2, 2010 So identify it like you did two lines above that one. You probably have to identify which one you want in the "order by" clause also. Ken Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142350 Share on other sites More sharing options...
mtvaran Posted December 3, 2010 Author Share Posted December 3, 2010 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); ?> Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142448 Share on other sites More sharing options...
btherl Posted December 3, 2010 Share Posted December 3, 2010 Does the query succeed and return 0 results, or does it fail? Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142455 Share on other sites More sharing options...
mtvaran Posted December 3, 2010 Author Share Posted December 3, 2010 yes now it works. i had to take echo mysql_error(); off. previously i put it for error finding. thanks guys for your kind help. Link to comment https://forums.phpfreaks.com/topic/220491-how-to-fix-where-clause-is-ambiguous-error/#findComment-1142554 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.