phpperson Posted October 17, 2013 Share Posted October 17, 2013 Ok so i'm making a working search but it not working like when i type C it's supposed to give me the peoples first name with the letter C but it's giving me the error message in the title. Here's The Code for my file "thephp.php": <?php ?> <!doctype html> <html> <head> <script type="text/javascript"> function findmatch() { if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById('results').innerHTML = xmlhttp.responseText; } } xmlhttp.open('GET', 'search.inc.php?search_text='+document.search.search_text.value, true); xmlhttp.send(); } </script> </head> <body> <form id="search" name="search"> Type a name: <input type="text" name="search_text" onKeyup="findmatch();"> </form> <div id="results"></div> </body> </html> And here is my code for the file "search.inc.php": <?php include 'datebase.inc.php'; if(isset($_GET['search_text'])) { echo $search_text = $_GET['search_text']; } $query = "SELECT `firstname` FROM `users` LIKE '".mysql_real_escape_string($search_text)."%'"; $query_run = mysql_query($query); while($query_row = mysql_fetch_assoc($query_run)) { echo $firstname = $query_row['firstname'].'<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/283038-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in-cxampphtdocssearchincphp-on-line-13/ Share on other sites More sharing options...
Barand Posted October 17, 2013 Share Posted October 17, 2013 If you read the FAQ for this forum first you would know that you get that error when the query fails. In this case you have a syntax error. You need a WHERE clause. Try $query = "SELECT `firstname` FROM `users` WHERE `firstname` LIKE '".mysql_real_escape_string($search_text)."%'"; Next time you post code, use the forum's [ code ]..[ /code ] tags or use the <> button in the toolbar Quote Link to comment https://forums.phpfreaks.com/topic/283038-warning-mysql_fetch_assoc-expects-parameter-1-to-be-resource-boolean-given-in-cxampphtdocssearchincphp-on-line-13/#findComment-1454237 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.