Hello, I had an error while compile this code. Can somebody help me.. I need the answer ASAP..Thank you

search.html

<form name="form" method="post" action="search0.php">
                Search by Matric No.:
                <input type="text" name="patron_ID" placeholder="Student No.">
                <input type="submit" name="Submit" value="Search">
          </form>

search0.php

<?php
/* include db connection file*/
include("dbconnect.php");

/* capture student number */
//$idsaja = $_POST['idsaja'];
$patron_ID = $_POST['patron_ID'];

/* execute SQL statement */
$sql= " SELECT br.patron_ID, p.patron_Name, br.book_Accession, b.book_Title, br.borrowed_Date,
                    br.discharged_Date, br.due_Date, b.book_Status

                    FROM borrow br
                    INNER JOIN patrons p 
                    ON p.patron_ID = br.patron_ID
                    JOIN book b
                    ON b.book_Accession = br.book_Accession
                    WHERE patron_ID = '$patron_ID'";

//"SELECT * FROM patrons WHERE patron_ID= '$patron_ID'";
$query = mysql_query($sql) or die ("Error: ".mysql_error());
$row = mysql_num_rows($query);

if($row == 0){
echo "No record found";
}
else{
$r = mysql_fetch_assoc($query);
$patron_ID = $r['patron_ID'];
$patron_Name = $r['patron_Name'];
$book_Accession = $r['book_Accession'];
$book_Title = $r['book_Title'];
$borrowed_Date = $r['borrowed_Date'];
$discharged_Date = $r['discharged_Date'];
$due_Date = $r['due_Date'];
$book_Status = $r['book_Status'];
?>

The error is "Error: Column 'patron_ID' in where clause is ambiguous". What that means?

Recommended Answers

All 3 Replies

Add one of the table aliases to the column, so:

WHERE br.patron_ID = '$patron_ID'";

The error happens because your using two tables with the same column name.

ohh thanks you it works! That mean I cant to use the same column name while join two table?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.