kaimason1 Posted March 1, 2009 Share Posted March 1, 2009 Unknown column 'Book' in 'where clause' Now I'm getting this error... help? EDIT:: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>My Search</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <FORM METHOD="get" action="search.php"> <P>Please enter your search words here and specify the type of data you input: <INPUT type="text" name="search" size=30 maxlength=70> <SELECT name="type" size="1"> <OPTION value="Title">Title</OPTION> <OPTION value="Author">Author</OPTION> <OPTION value="Genre">Genre</OPTION> <OPTION value="Page_Count">Page Count</OPTION> <OPTION value="Reading_Level">Reading Level</OPTION> <OPTION value="ISBN">ISBN</OPTION> </SELECT> </P> <INPUT type="submit" name="submit" value="Submit"> </FORM> </BODY> </HTML> <?php if(isset($_GET['submit']) && $_GET['submit'] == "Submit") { //Connect to database// include("usernamepassworddatabase.php"); mysql_connect(localhost,$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?"); mysql_select_db($database)or die("The database you are trying to access is currently unavailable. Curious..."); //Retrieve variables from HTML form $search=trim(mysql_real_escape_string($_GET['search'])); $type=trim(mysql_real_escape_string($_GET['type'])); //Create MySQL query// if($search == "") { die("Please enter a search."); } else if($type == "Title") { $query="SELECT * FROM TEST1_contacts WHERE 'Book' LIKE '%$search%'"; } else if($type == "Author") { $query="SELECT * FROM TEST1_contacts WHERE 'Author' LIKE '%$search%'"; } else if($type == "Genre") { $query="SELECT * FROM TEST1_contacts WHERE 'Genre' LIKE '%$search%'"; } else if($type == "Page_Count") { $query="SELECT * FROM TEST1_contacts WHERE 'Page_Count' LIKE '%$search%'"; } else if($type == "Reading_Level") { $query="SELECT * FROM TEST1_contacts WHERE 'Reading_Level' LIKE '%$search%'"; } else if($type == "ISBN") { $query="SELECT * FROM TEST1_contacts WHERE 'ISBN' LIKE '%$search%'"; } else{ die("Congratulations -- you achieved the impossible rating of hacker. How else did I receive an inaccurate data type, hmm?"); } //Search Results// $result=mysql_query($query) or die (mysql_error()); $num=mysql_num_rows($result); if($num == 0) { die("There seems to be no records matching your search. Interesting..."); } else{ $i=0; while($i<$num){ $book=mysql_result($result,$i,"Book"); $author=mysql_result($result,$i,"Author"); $genre=mysql_result($result,$i,"Genre"); $page_count=mysql_result($result,$i,"Page_Count"); $reading_level=mysql_result($result,$i,"Reading_Level"); $ISBN=mysql_result($result,$i,"ISBN"); echo("<b>$book</b> by $author.<br>$genre.<br>$page_count pages.<br>$reading_level reading level.<br>ISBN:$ISBN<br><hr><br>"); ++$i; } } } php?> Link to comment https://forums.phpfreaks.com/topic/147377-solved-important-error-message-making-me-feel-stupid/ Share on other sites More sharing options...
Philip Posted March 1, 2009 Share Posted March 1, 2009 The column 'Book' does not exist in your table, TEST1_contacts, on this line: $query="SELECT * FROM TEST1_contacts WHERE 'Book' LIKE '%$search%'"; Link to comment https://forums.phpfreaks.com/topic/147377-solved-important-error-message-making-me-feel-stupid/#findComment-773589 Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2009 Share Posted March 1, 2009 Putting single-quotes around column names make them strings instead of identifiers. Remove the single-quotes from around all your column names. Link to comment https://forums.phpfreaks.com/topic/147377-solved-important-error-message-making-me-feel-stupid/#findComment-773596 Share on other sites More sharing options...
RussellReal Posted March 1, 2009 Share Posted March 1, 2009 pfm is right, use ` ` instead of ' ' Link to comment https://forums.phpfreaks.com/topic/147377-solved-important-error-message-making-me-feel-stupid/#findComment-773604 Share on other sites More sharing options...
kaimason1 Posted March 1, 2009 Author Share Posted March 1, 2009 I just used the wrong table name... oops Link to comment https://forums.phpfreaks.com/topic/147377-solved-important-error-message-making-me-feel-stupid/#findComment-773605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.