php form

hi the following php code brings back a message on the screen sayin unknown column in where clause.

<?php

error_reporting(E_ALL);
if (!isset($_POST[‘Submit’])) {
// form not submitted

?>

search
search By... book ISBN book Title catID <?php } else { // form submitted // set server access variables $search = empty($_POST['search'])? die ("ERROR: Enter search Criteria") : mysql_escape_string($_POST['search']); $dropdown = empty($_POST['dropdown'])? die ("ERROR: Select from dropdown") : mysql_escape_string($_POST['dropdown']); // Open Connection //Select Database $conn = mysql_connect ('localhost', 'unn_w10019262', 'davidson') or die("Could Not Connect to MySQL!"); mysql_select_db("unn_w10019262") or die("Could Not Open Database:".mysql_error()); //Create Query $sql = "SELECT * FROM nbc_book WHERE bookTitle='$bookTitle'" or die (mysql_error()); $result = mysql_query($sql) or die (mysql_error()); $num=mysql_numrows($result); mysql_close($connect); echo "Database Output

"; $i=0; while ($i < $num) { $bookISBN=mysql_result($result,$i,"ISBN"); $bookTitle=mysql_result($result,$i,"Title"); $catID=mysql_result($result,$i,"catID"); echo "
bookISBN: $bookISBN

bookTitle: $bookTitle
catID: $catID
"; $i++; } } ?>

could someone help me please

The error is in your mysql query.

It is saying that there is no column called ‘bookTitle’

thanks for the reply im still confused on how to fix this… as you can see this is mysql query:
$sql = “SELECT * FROM nbc_book WHERE bookTitle=’$bookTitle’” or die (mysql_error());

$result = mysql_query($sql) or die (mysql_error());

it was previously where you have booktitle it was $search = $dropdown.
I want it so that when i type something in the search and choose a dropdown it produce a record for that dropdown for example if type gary in the search and select book title in dropdown it should display the books called gary under book title. please can you help me devise the code for that

It’s an error in your database not your code. in the table nbc_book, it is saying there is not a column called bookTitle (note this IS case sensitive)

the thing is that in my database there is a column called that. and for my other drop downs they bring the same error message aswell.
my columns are booktitle, bookisbn, catid pubid bookprice

Hi there,

What RaythXC is trying to say is that the columns are case-sensitive. Your code has bookTitle but your column is booktitle. You either have to put booktitle in your code, or change your column in your database to reflect that uppercase letter. Either way your code won’t work until you do that.

Hope that helps.

IVE CHECKED WHAT I TYPED AND IN MY DATABASe and the columns are called bookTitle and bookISBN and catID and thats exactly what i type in my code. and it still isnt working.

i typed ryan in my search page under book title dropdown because ryan is a book in my database and came out with this…: Unknown column ‘ryan’ in ‘where clause’

so i need an sql statement that will say when the user types something in the search bar and chooses a drop down box it will display the records it has for what they typed for under the drop down which consists of bookTitle, bookISBN and catID

Sponsor our Newsletter | Privacy Policy | Terms of Service