Hello I am trying to write a query that will take an variable from a form that has three fields: State drop down , text box and another drop down that has Entire Database, Book Title, Book Author and Book ISBN in it.
I then send all of the variables to my search script to bring back the results however I am having troubles getting every combination to work maybe one of the super php coders can help...here is the code I have:
<?php
$user = 'x';
$password = 'xxx';
$db = 'xxxx';
mysql_connect('64.156.138.234', $user, $password);
@mysql_select_db($db) or DIE('Unable to open database');
if ($search_in == "Entire Database" && $search_state== "") {
$query = "SELECT * FROM add_info where Book_name LIKE '%$search_text%'
OR Book_ISBN LIKE '%$search_text%' ";
}
else if ($search_in == "Entire Database" && $search_state) {
$query = "SELECT * FROM add_info where state= '$search_state' and (Book_name LIKE '%$search_text%'
OR Book_ISBN LIKE '%$search_text%' )";
}
else if ($search_in == "Book by Title" && $search_state) {
$query = "SELECT * FROM add_info where state= '$search_state' and (Book_name LIKE '%$search_text%' )";
}
else if ($search_in == "Book by Author" && $search_state) {
$query = "SELECT * FROM add_info where state= '$search_state' and (Book_author LIKE '%$search_text%' )";
}
else if ($search_in == "Book by ISBN" && $search_state) {
$query = "SELECT * FROM add_info where state= '$search_state' and (Book_ISBN LIKE '%$search_text%' )";
}
else if ($search_in == "Entire Database" ) {
$query = "SELECT * FROM add_info where Book_name LIKE '%$search_text%'
OR Book_ISBN LIKE '%$search_text%' ";
} else if ($search_in == "Book by Title"){
$query = "SELECT * FROM add_info where Book_name LIKE '%$search_text%'";
} else if ($search_in == "Book by Author") {
$query = "SELECT * FROM add_info where Book_author LIKE '%$search_text%'";
} else if ($search_in == "Book by ISBN") {
$query = "SELECT * FROM add_info where Book_ISBN LIKE '%$search_text%'";
}
$result = mysql_query($query);
while ($results = mysql_fetch_array($result)) {
echo("<TR>\n");
$id =$results["id"];
$first =$results["first"];
$email =$results["email"];
$city =$results["city"];
$state =$results["state"];
$college =$results["college"];
$phone =$results["phone"];
$Book_name =$results["Book_name"];
$Book_author =$results["Book_author"];
$Book_ISBN =$results["Book_ISBN"];
$Book_subject =$results["Book_subject"];
$Book_price =$results["Book_price"];
$first = stripslashes($first);
$email = stripslashes($email);
$city = stripslashes($city);
$state = stripslashes($state);
$college = stripslashes($college);
$phone = stripslashes($phone);
$Book_name = stripslashes($Book_name);
$Book_author = stripslashes($Book_author);
$Book_ISBN = stripslashes($Book_ISBN);
$Book_subject = stripslashes($Book_subject);
$Book_price = stripslashes($Book_price);
echo("<TD><a href='search_book.php?id=$id'>$Book_name</TD>\n");
echo("<td>$college</td>\n");
echo("<td>$state</td>\n");
echo("<td>$Book_price</td>\n");
echo("</TR>\n");
}
?>