Jump to content

Why my search engine Goes wrong Everytime I have User Logged In


Recommended Posts

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"/>





// my php search code searchcode.txt


$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){


if ($i==1) 

$query .= "search like '%$each%' ";


$query .= "Or search like '%$each%' "; 




mysql_connect("localhost", "root");


//Done if Search is filled



$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'/>












echo " <center>No results found for \"<b>$keysearch</b>\"";






Link to comment
Share on other sites

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
    // output the error from query
    trigger_error('Query has failed: ' . mysql_error());
Edited by Ch0cu3r
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
    // output the error from query
    trigger_error('Query has failed: ' . mysql_error());

    echo "Query: <pre>$query</pre>";
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.