Hi i'm trying to successfully get this PHP code to search MySQL database called test2
that has a table called questions, in that table there are columns called ID, Question, Category and Answer.
This code is an excerpt from a tutorial that allows you to search the mysql database for state names, i did it successfully but wherever i try to change the selecting the column name questions to display in the search results and change the db_name to test2, i just get the error
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search\getStates.php on line 10
here is my search.php
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test2") or die(mysql_error());
$partialStates = $_POST['partialStates'];
$states = mysql_query("SELECT question FROM questions WHERE name LIKE '%$partialStates%'");
while($state = mysql_fetch_array($states)) {
echo "<div>".$state['name']."</div>";
}
?>
here is my index.htm code
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function getStates(value){
$.post("getStates.php",{partialStates:value},function(data){
$("#results").html(data);
});
}
</script>
</head>
<body>
<input type="text" onKeyUp="getStates(this.value)" >
<br>
<div id="results"></div>
</body>
</html>
Can somebody assist me on this please? Thanks.