Jump to content

Error: Column 'column_Name' In Where Clause Is Ambiguous


EzwanAbid

Recommended Posts

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

Link to comment
Share on other sites

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.. :sweat:

Link to comment
Share on other sites

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 by EzwanAbid
Link to comment
Share on other sites

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 . :happy-04:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.