mcclellanfsu Posted February 22, 2007 Share Posted February 22, 2007 Hello, I have a simple html search form. I want to select what I will search for and then some search criteria. I am not getting any errors, but my problem is that nothing will show up...not even the count. Here are my two pages of code: search.html <body> <h1>Book-O-Rama Catalog Search</h1> <form action="results.php" method="post"> Choose Search Type:<br /> <select name="searchtype"> <option value="author">Author</option> <option value="title">Title</option> <option value="isbn">ISBN</option> </select> <br /> Enter Search Term:<br /> <input name="searchterm" type="text"> <br /> <input type="submit" value="Search"> </form> </body> and results.php <?php // create short variable names $searchtype=$_POST['searchtype']; $searchterm=$_POST['searchterm']; $searchterm= trim($searchterm); if (!$searchtype || !$searchterm) { echo 'You have not entered search details. Please go back and try again.'; exit; } if (!get_magic_quotes_gpc()) { $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } $db=mysql_connect ("localhost", "xxxxxx_booktst", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxx_bookorama"); $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = mysql_query($query); //Change made here -- used to be $db->query $num_results = $result->num_rows; echo '<p>Number of books found: '.$num_results.'</p>'; for ($i=0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); echo '<p><strong>'.($i+1).'. Title: '; echo htmlspecialchars(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>'; } //mysql_free_result($result); Wouldn't work so I commented it out for now. mysql_close(); ?> </body> Thank you in advance for any help you can give me! Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/ Share on other sites More sharing options...
JBS103 Posted February 22, 2007 Share Posted February 22, 2007 I am unsure where the following line comes from. It seems that $num_results is not getting set and therefore the for loop refuses to run. $num_results = $result->num_rows; Try changing that to $num_results = mysql_num_rows($result); Maybe I am missing something. Excuse me if I am. Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/#findComment-191450 Share on other sites More sharing options...
Neptunus Maris Posted February 22, 2007 Share Posted February 22, 2007 take out the exit; or if you want to display a message AND exit the script...die("Your error message"); Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/#findComment-191451 Share on other sites More sharing options...
mcclellanfsu Posted February 22, 2007 Author Share Posted February 22, 2007 Thank you for your responses. That did fix a couple of the problems, but now there is another one. This is the error I get: Fatal error: Call to a member function on a non-object in /home/mcclella/public_html/booktest/results.php on line 37 This is line 37: $row = $result->fetch_assoc(); The rest of the code: <?php // create short variable names $searchtype=$_POST['searchtype']; $searchterm=$_POST['searchterm']; $searchterm= trim($searchterm); if (!$searchtype || !$searchterm) { die("You have not entered search details. Please go back and try again."); } if (!get_magic_quotes_gpc()) { $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); } $db=mysql_connect ("localhost", "xxxxxx_booktst", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("xxxxxx_bookorama"); $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = mysql_query($query) or die('Error, search query failed'); $num_results = mysql_num_rows($result); echo '<p>Number of books found: '.$num_results.'</p>'; for ($i=0; $i < $num_results; $i++) { $row = $result->fetch_assoc(); echo '<p><strong>'.($i+1).'. Title: '; echo htmlspecialchars(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>'; } mysql_close(); ?> Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/#findComment-191543 Share on other sites More sharing options...
magic2goodil Posted February 22, 2007 Share Posted February 22, 2007 instead of: $row = $result->fetch_assoc(); try: $row = mysql_fetch_assoc($result) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/#findComment-191550 Share on other sites More sharing options...
mcclellanfsu Posted February 22, 2007 Author Share Posted February 22, 2007 Wahoo! Thank you very much! I'm so glad I found this site. Thank you to everyone who has been helping me out! Link to comment https://forums.phpfreaks.com/topic/39659-solved-results-showing-blank-page/#findComment-191594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.