Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 Here is all the code displaying the html then the php code. <form action="results.php" method="post"> Choose Search Type:<br> <select name="searchtype"> <option value="author">Author <option value="title">Title <option value="isbn">ISBN </select> <br> Enter Search Term:<br> <input name="searchterm" type=text> <br> <input type=submit value="Search"> </form> <? $searchtype = addslashes($_POST['searchtype']); $searchterm = addslashes($_POST['searchterm']); if (!$searchtype || !$searchterm) { echo "You have not entered search details. Please go back and try again."; exit; } /* $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm);*/ $db = mysql_pconnect("localhost", "bookorama"); if (!$db) { echo "Error: Could not connect to database. Please try again later."; exit; } mysql_select_db("bookorama"); $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; //$query = "select * from books"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0; $i <$num_results; $i++) { $row = mysql_fetch_array($result); echo "<p><strong>".($i+1).". Title: "; echo stripslashes($row["title"]); echo "</strong><br>Author: "; echo stripslashes($row["author"]); echo "<br>ISBN: "; echo stripslashes($row["isbn"]); echo "<br>Price: "; echo stripslashes($row["price"]); echo "</p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-218896 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 First change $searchtype = addslashes($_POST['searchtype']); $searchterm = addslashes($_POST['searchterm']); to $searchtype = $_POST['searchtype']; $searchterm = $_POST['searchterm']; echo "searchtype = $searchtype<BR>" echo "searchterm = $searchterm <BR>" and try that see what the return page echos Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-218904 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 First change $searchtype = addslashes($_POST['searchtype']); $searchterm = addslashes($_POST['searchterm']); to $searchtype = $_POST['searchtype']; $searchterm = $_POST['searchterm']; echo "searchtype = $searchtype<BR>" echo "searchterm = $searchterm <BR>" and try that see what the return page echos searchtype = author searchterm = author Number of books found: 0 Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-218927 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 can you post a few records from the database Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-218977 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 can you post a few records from the database // I am able to post a few records by using $query = "select * from books"; // but not by using $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219135 Share on other sites More sharing options...
AndyB Posted April 1, 2007 Share Posted April 1, 2007 Create a record of something where the author was Bob. Use your search form to enter author as the search type and bob as the search term. Do you get a record back? If so, good. If not, are you sure all files are on the same server as the database and current, etc. If you get an error please tell us what it is. Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219140 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 Andy B, ok I got that part working thanks to you, but now I need to populate a Drop Down Menu. I have some code that I wrote that will populate the Drop Down Menu pulling data from the database but I am unable to select data from the menu so that the menu will populate a table. // Calling Function For Drop Down Menu Populating_DDM(); function Populating_DDM(){ global $num_results,$result; echo "<select name=searchtype value=''>Sponsor</option>"; // printing the list box select command for ($i = 0; $i < $num_results; $i++) { $row = mysql_fetch_array($result); echo "<option value=$row[$i]>$row[sponsor]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box }// End of function Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219172 Share on other sites More sharing options...
swatisonee Posted April 1, 2007 Share Posted April 1, 2007 Theres a good drop down "ready" code here. Follow the link. And i cannot beleive you didnt take Barands help ! http://www.plus2net.com/php_tutorial/php_drop_down_list.php Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219174 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 I got about three different windows open trying to make one complete code, and that code is one of my windows. Thanks anyway. Do you have any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219183 Share on other sites More sharing options...
swatisonee Posted April 1, 2007 Share Posted April 1, 2007 No. Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219187 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 OK FINE!! What does $query = "select * from books"; show ? can you post a few records from the database // I am able to post a few records by using $query = "select * from books"; // but not by using $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219210 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 OK FINE!! What does $query = "select * from books"; show ? can you post a few records from the database // I am able to post a few records by using $query = "select * from books"; // but not by using $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $query = "select * from books"; /* This is all the data in my database. Name Age State Sponsor Jordan 45 NC Phil Jackson Bryant 30 LA Phil Jackson Shaq 33 MIA Pat Riley */ Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219255 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 echo "<p><strong>".($i+1).". Title: "; echo stripslashes($row["title"]); echo "</strong><br>Author: "; echo stripslashes($row["author"]); echo "<br>ISBN: "; echo stripslashes($row["isbn"]); echo "<br>Price: "; echo stripslashes($row["price"]); echo "</p>"; produces this /* This is all the data in my database. Name Age State Sponsor Jordan 45 NC Phil Jackson Bryant 30 LA Phil Jackson Shaq 33 MIA Pat Riley */ from $query = "select * from books"; Well thats amazing erm.. try the echo "<p><strong>".($i+1).". Title: "; echo stripslashes($row["title"]); echo "</strong><br>Author: "; echo stripslashes($row["author"]); echo "<br>ISBN: "; echo stripslashes($row["isbn"]); echo "<br>Price: "; echo stripslashes($row["price"]); echo "</p>"; to echo "<p><strong>".($i+1).". Name: "; echo stripslashes($row["Name"]); echo "</strong><br>Age: "; echo stripslashes($row["Age"]); echo "<br>State: "; echo stripslashes($row["State"]); echo "<br>Sponsor: "; echo stripslashes($row["Sponsor"]); echo "</p>"; and Good Luck Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219262 Share on other sites More sharing options...
Trium918 Posted April 1, 2007 Author Share Posted April 1, 2007 No!! for ($i = 0; $i < $num_results; $i++) { $row = mysql_fetch_array($result); $name = htmlspecialchars( stripslashes($row["name"])); $age = htmlspecialchars( stripslashes($row["age"])); $state = htmlspecialchars( stripslashes($row["state"])); $sponsor = htmlspecialchars( stripslashes($row["sponsor"])); // Output echo " <tr> <td>$name</td> <td>$age</td> <td>$state</td> <td>$sponsor</td>"; }// End of For loop Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219264 Share on other sites More sharing options...
MadTechie Posted April 1, 2007 Share Posted April 1, 2007 i don't know how to help you sorry.. Quote Link to comment https://forums.phpfreaks.com/topic/45057-solved-drop-down-menu/page/2/#findComment-219266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.