ava5193 Posted January 14, 2014 Share Posted January 14, 2014 GOOD DAY phpfreaks.com Can Anyone Help about my code. My search engine can search and display if there is no user logged-in, but it goes wrong when it have user logged-in ? //The Error Shown Every time I have user Loginerror.txt Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\pagong\ProgramFiles\wamp\www\mandaya\pages\modifier\search.php on line 103 //The Search Form search-form.txt <form action="search.php" method="get" id="form1" name="form1" > <input name="keysearch" type="text" value="<?php echo $_GET['keysearch']; ?>" size="30" height="30px" placeholder="Search Mandaya Topics" id="s_box" /> <input type="submit" value="SEARCH" class="s_in"/> </form> // my php search code searchcode.txt <?php $keysearch = $_GET['keysearch']; $keysearch = filter_var($_GET['keysearch'], FILTER_SANITIZE_STRING); $keysearch = htmlspecialchars($_GET['keysearch']); $terms = explode(" ", $keysearch); $query = "Select * from images Where "; foreach ($terms as $each){ $i++; if ($i==1) $query .= "search like '%$each%' "; else $query .= "Or search like '%$each%' "; } //connect mysql_connect("localhost", "root"); mysql_select_db("mandaya"); //Done if Search is filled if(!empty($keysearch)){ $query = mysql_query($query); //Execute the query $query $numrows = mysql_num_rows($query); //Count the result of query //Get the DB fields from query if ($numrows > 0 ){ //Set each other while ($row = mysql_fetch_assoc($query)){ $id_topic = $row ['id_img']; $title = $row ['title']; $description = $row ['description']; $a = $row ['desc_a']; $b = $row ['desc_b']; $c = $row ['desc_c']; $d = $row ['desc_d']; $e = $row ['desc_e']; $link1 = $row ['link1']; $link2 = $row ['link2']; $key = $row ['keywords']; echo "<ul class='image_list'> <li><form method='POST' action='index.php'> <input type='hidden' name='topic' value='$id_topic'/> <input type='hidden' name='title' value='$title'/> <input type='image' name='img' value='$link1' src='$link1' size='100px' height='100px' title='$title'/> <input type='hidden' name='desc' value='$description'/> <input type='hidden' name='desc_a' value='$a'/> <input type='hidden' name='desc_b' value='$b'/> <input type='hidden' name='desc_c' value='$c'/> <input type='hidden' name='desc_d' value='$d'/> <input type='hidden' name='desc_e' value='$e'/> <input type='hidden' name='key' value='$key'/> <input type='hidden' name='image1' value='$link1'/> <input type='hidden' name='image' value='$link2'/> </form></li> </ul>"; } } else echo " <center>No results found for \"<b>$keysearch</b>\""; } //disconnect mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/285361-why-my-search-engine-goes-wrong-everytime-i-have-user-logged-in/ Share on other sites More sharing options...
Ch0cu3r Posted January 14, 2014 Share Posted January 14, 2014 (edited) Your query is most probably returning an error. Check that they query has executed ok before getting the results $query = mysql_query($query); //Execute the query $query // when mysql returns an error, mysql_query will return false if(!$query) { // output the error from query trigger_error('Query has failed: ' . mysql_error()); } Edited January 14, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285361-why-my-search-engine-goes-wrong-everytime-i-have-user-logged-in/#findComment-1465210 Share on other sites More sharing options...
ava5193 Posted January 16, 2014 Author Share Posted January 16, 2014 Thnx for reply Ch0cu3r You are right When i try it... it added new error: and i cant understand it? pls help what does this mean? // I search for aa Notice: Query has failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Or search like ('%aa%')' at line 1 in E:\pagong\ProgramFiles\wamp\www\mandaya\pages\modifier\seach_topics.php on line 108 Quote Link to comment https://forums.phpfreaks.com/topic/285361-why-my-search-engine-goes-wrong-everytime-i-have-user-logged-in/#findComment-1465425 Share on other sites More sharing options...
Ch0cu3r Posted January 16, 2014 Share Posted January 16, 2014 Your code is generating the mysql query, for some reason it is causing an error in the query. Echo your query to see if its formatted correctly, // when mysql returns an error, mysql_query will return false if(!$query) { // output the error from query trigger_error('Query has failed: ' . mysql_error()); echo "Query: <pre>$query</pre>"; } Quote Link to comment https://forums.phpfreaks.com/topic/285361-why-my-search-engine-goes-wrong-everytime-i-have-user-logged-in/#findComment-1465426 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.