you will get
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/p/i/c/pickageek/html/alpha/searchx.php on line 52
What is going on in there???
this is the page code
Code: Select all
<?php
print <<<_HTML_
<BODY>
<h1> Pickageek DB Search<hr></h1>
<form method="post" action="">
<table width="396" border="0">
<tr>
<td width="80"><div align="left">User name</div></td>
<td width="306"><input name="user_name" type="text" value = "$_POST[user_name]" size="40"></td>
</tr>
<tr>
<td><div align="left">Interest</div></td>
<td><input name="interest" type="text" value = "$_POST[interest]" size="40"></td>
</tr>
<tr>
<td><div align="left">Rating</div></td>
<td><input type="text" name="rating" value = "$_POST[rating]"></td>
</tr>
<tr>
<td><div align="left">Completed</div></td>
<td><input type="text" name="completed" value = "$_POST[completed]" ></td>
</tr>
<tr>
<td height="45"><input type="submit" name="Submit" value="Search"></td>
<td> </td>
</tr>
</table>
</form>
</BODY>
_HTML_;
if ($_POST['Submit']){
//if submit button is pressed
$where = '';
if($_POST['user_name'] != '')
$where .= (($where=='') ? 'where ' : ' AND ') . "username like '" . str_replace("*" ,"%",$_POST['user_name'] . "*") . "'";
if($_POST['interest'] != '')
$where .= (($where=='') ? 'where ' : ' AND ') ."((expertise like " . str_replace("*","%",$_POST['interest']) . ") OR (resume like " . str_replace("*","%",$_POST['interest']) . "))";
if($_POST['rating'] != '')
$where .= (($where=='') ? 'where ' : ' AND ') . "(rating >= " . $_POST['rating'] . ")";
if($_POST['completed'] != '')
$where .= (($where=='') ? 'where ' : ' AND ') . "(Comprojects = " . $_POST['completed'] . ")";
//blank where means no search is selected so no need to perform any DB operation
if ($where !=''){
$link = mysql_connect('mysql127.secureserver.net','root','pass') or die('Database connection Error!!');
mysql_select_db('pickageek');
$query = "Select username,rating,points,expertise,resume from users " . $where ;
print "<B>Query string: <br>" . $query . '<br>Results:<br>';
$result_set = mysql_query($query);
while ($row = mysql_fetch_assoc($result_set)) {
print $row['username'] .
" rated: " . $row['rating'] .
" points: " . $row['points'] . "<br>";
}
mysql_free_result($result_set);
mysql_close($link);
}
}
?>