Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\php1\htdocs\search.php on line 49
when I run my code
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/xml; charset=utf-8" />
<title>search.php</title>
<style type = "text/css">
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>My Contacts</h1>
<?php
$sql = processInput();
printResults($sql);
function processInput(){
$srchVal = $_POST["srchVal"];
$srchField = $_POST["srchField"];
$conn = mysql_connect("localhost", "root", "apollo66");
$sql = "SELECT * FROM contact WHERE $srchField LIKE '%$srchVal%'";
return $sql;
}
function printResults($sql){
$conn = mysql_connect("localhost", "root", "apollo66");
mysql_select_db("sb");
$result = mysql_query($sql, $conn);
print " <table> \n";
print " <tr> \n";
while ($field = mysql_fetch_field($result)){
print " <th>$field->name</th> \n";
}
print " </tr> \n";
while ($row = mysql_fetch_assoc($result)){
print " <tr> \n";
foreach ($row as $name => $value){
print " <td>$value</td> \n";
}
print " </tr> \n";
}
print " </table> \n";
}
?>
</body>
</html>
Any Idea what the problem is and how I can fix it?