EzwanAbid Posted December 12, 2012 Share Posted December 12, 2012 I'm trying to display certain data from database phpmyadmin by inserting 'student_id' in my search box... but after I submit the data inside the search box, I get this error message in my html page.. Error: Column 'student_id' in where clause is ambiguous In Query: SELECT * FROM student,surat WHERE student_id like '%12-121212-1212%' Is there something wrong with my phpmyadmin or my php code? Here my full php code named "searchres.php" : <?php $host_name = "localhost"; $user_name = "root"; $password = ""; $db_name = "finalproject"; $StudentID1=$_POST['Field0']; $StudentID2=$_POST['Field1']; $StudentID3=$_POST['Field2']; $term =$StudentID1.-$StudentID2.-$StudentID3; mysql_connect("$host_name" , "$user_name" , "$password"); mysql_select_db("$db_name"); $sql = "SELECT * FROM student,surat WHERE student_id like '%$term%' AND student.student_id=surat.student_id" ; $query = mysql_query($sql) or die("Error: " . mysql_error() . "<br />In Query: " . $sql); while ($row = mysql_fetch_array($query)){ echo 'Student ID: '.$row['student_id']; echo '<br/> Fullname: '.$row['fullname']; echo '<br/> IC No.: '.$row['ic_number']; echo '<br/> Course: '.$row['course']; echo '<br/> Type Of Letter: '.$row['jenissurat']; echo '<br/><br/>'; } ?> I'm new in php and mysql, the code above I take it from google and edit some of the code by myself according to my usage. Hope someone can give me an advice,solution or corrections maybee.. Thank You. I already upload my php file here. Search.php searchres.php Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/ Share on other sites More sharing options...
MDCode Posted December 12, 2012 Share Posted December 12, 2012 If both tables have a student_id column you need to specify which table to select it from. Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1398986 Share on other sites More sharing options...
EzwanAbid Posted December 12, 2012 Author Share Posted December 12, 2012 If both tables have a student_id column you need to specify which table to select it from. Do you mean from my phpmyadmin? If that so.. my mysql code below is wrong? $sql = "SELECT * FROM student,surat WHERE student_id like '%$term%' AND student.student_id=surat.student_id" ; I think my direction in this code are correct.. maybee.. Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1398991 Share on other sites More sharing options...
MDCode Posted December 12, 2012 Share Posted December 12, 2012 If in your database, the tables student and surat both have a student_id column you need to specify which one to select it from in WHERE student_id like '%$term%' Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1398994 Share on other sites More sharing options...
EzwanAbid Posted December 12, 2012 Author Share Posted December 12, 2012 (edited) Thank you for your reply. But how to specify it? Sorry because I'm new in PHP and MySQL .. :-\ Sorry for that. The table that I have is student : student_id : 12-121212-12121 fullname : EZWAN ic_number : 121212-12-1212 password : course : IT-Software surat : id_surat : 1 studennt_id : 12-121212-12121 jenissurat : TamatBelajar status : Edited December 12, 2012 by EzwanAbid Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1399002 Share on other sites More sharing options...
EzwanAbid Posted December 12, 2012 Author Share Posted December 12, 2012 I hope this can help my explanation.. I'm trying to send image here.. but I don't know how.. lol Sorry for that. Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1399005 Share on other sites More sharing options...
MDCode Posted December 12, 2012 Share Posted December 12, 2012 (edited) $sql = "SELECT * FROM student,surat WHERE table_name.student_id like '%$term%' AND student.student_id=surat.student_id"; Edited December 12, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1399009 Share on other sites More sharing options...
EzwanAbid Posted December 12, 2012 Author Share Posted December 12, 2012 Did you mean $sql = "SELECT * FROM student,surat WHERE table_name.student_id like '%$term%' AND student.student_id=surat.student_id"; I'm using this code and IT'S WORKING !! I already can display data from both table using search now.. Thank you alot !! I'm stuck with this problem for over 2 weeks .. :'( Thank You @SocialCloud for helping me . Quote Link to comment https://forums.phpfreaks.com/topic/271925-error-column-column_name-in-where-clause-is-ambiguous/#findComment-1399013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.