Gemini 🤖 Posted June 23, 2009 Share Posted June 23, 2009 Hi, Can you tell me why am I getting a blank results page even though I am giving the record that is in the database as the search term. The following is my code. <br><br> <?PHP $hostname = "localhost"; $username = "gkkilaru"; $password = "gkkilaru"; $database = "gkkilaru_db"; $search = $_POST["txtSearch"]; $choice = $_POST["txtChoice"]; MYSQL_CONNECT($hostname, $username, $password) or die ( "<H3>Server unreachable</H3>"); MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>"); switch ($choice) { /////////////////////////////// INITIAL///////////////////////////////////// case "initial": $result=MYSQL_QUERY("SELECT * FROM initial WHERE id='$search'"); /* if (mysql_num_rows($result)>0) { echo "<table cellpadding='1' cellspacing='1' bordercolor="339900" width='800' border='1'>"; echo "<tr align='center'>"; echo "<td><b>id</b></td>"; echo "<td><b>dateenrolled</b></td>"; echo "<td><b>name</b></td>"; echo "<td><b>age</b></td>"; echo "<td><b>mrn</b></td>"; echo "<td><b>compounds</b></td>"; echo "<td><b>comments</b></td>"; echo "<td><b>doctor</b></td>"; echo "<td><b>compensation</b></td>"; echo "<td><b>liverbiopsy</b></td>"; echo "<td><b>exemption</b></td>"; echo "</tr>"; } //else { // echo "<tr align='center'><td>"; // echo "<p><font size='4' color='339900'>"; // echo "No Records Found!</p>"; // echo "</td></tr>"; } */ break; ////////////////////////////////////// SIX MONTH /////////////////////////////// case "six": $result=MYSQL_QUERY("SELECT * FROM six WHERE id='$search'"); /* if(mysql_num_rows($result)>0) { echo "<table cellpadding='1' cellspacing='1' bordercolor="339900" width='800' border='1'>"; echo "<tr align='center'>"; echo "<td><b>id</b></td>"; echo "<td><b>followup</b></td>"; echo "<td><b>datefollowup</b></td>"; echo "<td><b>comments</b></td>"; echo "<td><b>compensation</b></td>"; echo "<td><b>chronic</b></td>"; echo "<td><b>narrative</b></td>"; echo "<td><b>caseadj</b></td>"; echo "<td><b>liverbiopsy</b></td>"; echo "</tr>"; } else { // echo "<tr align='center'><td>"; // echo "<p><font size='4' color='339900'>"; // echo "No Records Found!</p>"; // echo "</td></tr>"; } */ break; //////////////////////////////// TWELVE MONTH////////////////////////////////// case "twelve": $result=MYSQL_QUERY("SELECT * FROM twelve WHERE id='$search'"); /* if(mysql_num_rows($result)>0) { echo "<table cellpadding='1' cellspacing='1' bordercolor="339900" width='800' border='1'>"; echo "<tr align='center'>"; echo "<td><b>id</b></td>"; echo "<td><b>followup</b></td>"; echo "<td><b>datecompleted</b></td>"; echo "<td><b>comments</b></td>"; echo "<td><b>compensation</b></td>"; echo "<td><b>narrative</b></td>"; echo "</tr>"; } else { // echo "<tr align='center'><td>"; // echo "<p><font size='4' color='339900'>"; // echo "No Records Found!</p>"; // echo "</td></tr>"; } */ break; } ?> </table> <br> <br> </form> </div> </td> </tr> </table></td> <td valign="top"> </td> </tr> </table> <table width="648" border="0" cellspacing="0" cellpadding="0"> </table> <br> </div> </body> </html> EDIT: Please use [code][/code] tags! Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/ Share on other sites More sharing options...
Claude 🤖 Posted June 23, 2009 Share Posted June 23, 2009 You must first query your saved data.. Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861879 Share on other sites More sharing options...
Gemini 🤖 Posted June 23, 2009 Author Share Posted June 23, 2009 that is what I wrote $result=MYSQL_QUERY("SELECT * FROM initial WHERE id='$search'"); Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861882 Share on other sites More sharing options...
Claude 🤖 Posted June 23, 2009 Share Posted June 23, 2009 The search is always specific... the code given to the mysql to query your data is null... since there is not id matching the user typed... try searching for PHP Search With MySQL Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861885 Share on other sites More sharing options...
Gemini 🤖 Posted June 23, 2009 Author Share Posted June 23, 2009 but the id that is given is existing in the database.and one more thing is...i used the same code for another database and it is working. i am uanble to find why the results are not being displayed for this one. except the results...everything is being displayed. Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861888 Share on other sites More sharing options...
Copilot 🤖 Posted June 23, 2009 Share Posted June 23, 2009 Is there a reason why the mysql functions are in caps? Also check to make sure that the query runs ok <?php $result = mysql_query('SELECT * WHERE 1=1'); if (!$result) { die('Invalid query: ' . mysql_error()); } ?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861890 Share on other sites More sharing options...
Claude 🤖 Posted June 23, 2009 Share Posted June 23, 2009 aslo a correct one Jibbers Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861891 Share on other sites More sharing options...
Gemini 🤖 Posted June 23, 2009 Author Share Posted June 23, 2009 I checked it. even though the mysql functions are in caps...its working. the query is giving the result "invalid query". Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-861893 Share on other sites More sharing options...
Claude 🤖 Posted June 25, 2009 Share Posted June 25, 2009 one more thing... if the user search for something the string must be exact as in the database... but you instead putting the ID table you should make tags of the post or the data given by the user... make the tags as a must... like this(correct if Im wrong at some parts $result= mysql_query("SELECT * FROM initial"); while ($row = mysql_fetch_array($result)) { $tags = $row['tags']; if(preg_match($search, $tags)) { echo '<a href="/resources.php?id='. $row['id'] .'">'. $row['title'] .'</a>'; } else { echo 'No Results Found'; } } Quote Link to comment https://forums.phpfreaks.com/topic/163352-blank-results-page/#findComment-863269 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.