Hey guys new to the forum and also my reason for registering! so hi lol I have a search form on index.php that keeps giving me this error form follows as is... <form action="search.php" method="post"> <input type="text" value="Search on this website" name="q" size="10" id="searchfield" title="searchfield" onfocus="clearText(this)" onblur="clearText(this)" /> <input type="submit" name="Search" value="search" id="searchbutton" title="Search" /></form> PHP: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/blameyo/public_html/search.php on line 31 the search.php page contains the script <?php $input = $_GET['input']; $terms = explode(" ", $input); $query = "SELECT * FROM search WHERE "; foreach ($terms as $each) { $i++; if ($i == 1) $query .= "keywords LIKE '%each%' "; else $query .= "keywords LIKE '%each%' "; } //Connect to Database mysql_connect ('xxxxx', 'xxxxxxx', 'xxxxxxx'); mysql_select_db ("xxxxxxxx"); $query = mysql_query($query); $numrows = mysql_num_rows($query); if ($numrows > 0) { while ($row = mysqlfetch_assoc($query)){ $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2> $description<br/><br/>"; } } else echo "No results found for \"<b>$input</b>\""; //Disconnect mysql_close(); ?> PHP: you think it maybe a script problem or how i set up my database in myadmin ?
without seeing your full query i can only assume that your missing and AND also, Shouldn't it be '%$each%' Also your mixing your variables strangely!, it's bad practice to use variables for one thing and assign them to another thing, try $query_results = mysql_query($query); PHP:
hey thanks for the reply guys, and I'm new to php and decided to write the script as is in a txt pad following a tutorial on youtube. i get this error after writing in what wren11 asked me to try Warning: mysql_num_rows() expects parameter 1 to be resource, string given in /home/blameyo/public_html/search.php on line 32 full query is <html xmlns=""> <body> <h1 style="color;#09F; font-size;36px;">SEARCH</h1> <form action"search.php" method="get"> <input type="text" name="input" size"50" <?php echo $_GET ['input']; ?> /> <input type="submit" value="search" /> </form> <hr/> <?php $input = $_GET['input'];//Note to self $input in the name of the search feild $terms = explode(" ", $input); $query = "SELECT * FROM search WHERE "; foreach ($terms as $each){ $i++; if ($i == 1) $query .= "keywords LIKE '%$each%' "; else $query .= "OR keywords LIKE '%$each%' "; } // connecting to our mysql database mysql_connect("localhost", "blameyo_xxx", "xxx"); mysql_select_db("blameyo_xxx"); $query_results = mysql_query($query); $numrows = mysql_num_rows($query); if ($numrows > 0){ while ($row = mysql_fetch_assoc($query)){ $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2> $description<br /><br />"; } } else echo "No results found for \"<b>$input</b>\""; // disconnect mysql_close(); ?> </body> </html> PHP:
Try this: $query_results = mysql_query($query); $numrows = mysql_num_rows($query_results, $conn); // $conn should be the link to the connection if ($numrows > 0) { while ($row = mysql_fetch_assoc($query_results)) { $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2>$description<br /><br />"; } } else echo "No results found for \"<b>$input</b>\""; PHP:
If not, I think this should work? $conn = mysql_connect("localhost", "xxxx", "xxxx"); mysql_select_db("blameyo_xxx"); $query_results = mysql_query($query, $conn); if (isset($query_results)) { while ($row = mysql_fetch_array($query_results)) { $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2>$description<br /><br />"; } } else echo "No results found for \"<b>$input</b>\""; PHP:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/blameyo/public_html/search.php on line 37 thats my error code now. i have index.php and search.php both in public_html so that should be right ? ummm i created the database as it is in the script and table as well which is search dunno :| ill check that out though
im not yeilding any results. my last test gave me this as an error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/blameyo/public_html/search.php on line 18 script now as in the php manual <?php $input = $_GET['input'];//Note to self $input in the name of the search feild $terms = explode(" ", $input); $query = "SELECT * FROM search WHERE "; foreach ($terms as $each){ $i++; if ($i == 1) $query .= "keywords LIKE '%$each%' "; else $query .= "OR keywords LIKE '%$each%' "; } $link = mysql_connect("localhost", "blameyo_xxx", "xxx"); mysql_select_db("blameyo_xxx", $link); $result = mysql_query("SELECT * FROM search", $link); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; if ($numrows > 0){ while ($row = mysql_fetch_assoc($query)){ $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2> $description<br /><br />"; } } else echo "No results found for \"<b>$input</b>\""; // disconnect mysql_close(); ?> PHP:
<?php $input = $_GET['input']; $terms = explode(" ", $input); $query = "SELECT * FROM `search` WHERE "; $i = 0; foreach ($terms as $each) { if (($i++ % 2) == 0) $query .= "`keywords` LIKE '%$each%' "; else $query .= "OR `keywords` LIKE '%$each%' "; } $link = mysql_connect("127.0.0.1", "xxx", "xxx"); mysql_select_db("blameyo_xxx", $link); $results = mysql_query($query, $link); if (mysql_num_rows($results) > 0) { while ($row = mysql_fetch_Array($results)) { echo $row['ID'] . "<BR />"; } } else { echo "No Results found."; } mysql_close($link); ?> PHP: I tested this on my computer and it worked
im gonna record a short video of what im doing and hopefully my errors will be shown. be back in a short while !
please watch guys. It's 15 mins long but detailed from the start and hopefully will show some error of mine in the process. it starts off with me making the database! thanks. commentary included
This should be working, Change the db stuff to yours <html xmlns=""> <body> <h1 style="color;#09F; font-size;36px;">SEARCH</h1> <form action="search.php" method="get"> <input type=text name=input size=50> <input type="submit" value="search" /> </form> <hr/> <?php $input = $_GET['input']; if (isset($input)) { $terms = explode(" ", $input); $query = "SELECT * FROM `search` WHERE "; $i = 0; foreach ($terms as $each) { if (($i++ % 2) == 0) $query .= "`keywords` LIKE '%$each%' "; else $query .= "OR `keywords` LIKE '%$each%' "; } $link = mysql_connect("localhost", "tester", "xxxx"); mysql_select_db("xxx", $link); $results = mysql_query($query, $link); if (mysql_num_rows($results) > 0) { while ($row = mysql_fetch_Array($results)) { $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2>$description<br /><br />"; } } else { echo "No Results found."; } mysql_close(); } ?> </body> </html> PHP: Working Example: http://www.citfree.com/dp/search.php (search for test)
hey wren11 i think this is a better script. i dont get the error when i click search on the index.php but yeild no results and when i do click search on the search.php i get an error and nor do i yeild results Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/blameyo/public_html/search.php on line 39 in my videos theres "insert" where i have to enter a description, ID a link and whatever else. could that be where the problem lies ? it may not be the script
okay, you must have a problem on the database end my friend, as That script is working for me on my database, If you want you can PM me your DB test info and i can test it for you.
hey thanks alot for your help and patience wren11. I figured out what I was doing wrong that night... the user has to have all privileges enabled. I never gave the user privileges because i didn't understand what it was doing like giving the visitor permission to do this and that... but that corrected my boolean error. i gave you best answer since you cant go wrong with someone personally helping you so thanks again!