Forum Moderators: coopster
I've been working with PHP for a while but it's the first time I get this error. Here is my code:
<?
$type = $_GET['type'];
if ($type) {
if ($type=="web") {
function redirection($page) {
echo "<script language='Javascript'>";
echo "<!--\n";
echo "location.href = '$page';\n";
echo "// -->";
echo "</script>\n";
}
redirection("google.com/ssss"); }
elseif ($type=="leb") $result = mysql_query("SELECT * FROM lebweb WHERE title LIKE '%$q%' ¦¦ desc LIKE '%$q%'", $db);
elseif ($type=="polls") $result = mysql_query("SELECT * FROM poll_list WHERE question LIKE '%$q%'", $db);
elseif ($type=="blogs") $result = mysql_query("SELECT * FROM blog_list WHERE title LIKE '%$q%' ¦¦ desc LIKE '%$q%' ¦¦ link LIKE '%$q%' ¦¦ author LIKE '%$q%'", $db);
elseif ($type=="classifieds") $result = mysql_query("SELECT * FROM classifieds_list WHERE itemname LIKE '%$q%' ¦¦ desc LIKE '%$q%'", $db);
elseif ($type=="fanlistings") $result = mysql_query("SELECT * FROM fan_list WHERE title LIKE '%$q%' ¦¦ name LIKE '%$q%'", $db);
elseif ($type=="published") $result = mysql_query("SELECT * FROM publication_list WHERE title LIKE '%$q%' ¦¦ content LIKE '%$q%' ¦¦ author LIKE '%$q%'", $db);
else die("Invalid search type.");
}
$aff = mysql_affected_rows();
echo $aff;
?>
So, when I search for a term that is present once in the database, it returns -1 affected rows. When I search for a term that is present 2 or more times in my database, it returns all rows with the correct number of rows.
However, when I run a search on the polls table, everything is fine.
Are my queries wrong? Thanks, guys.
All suggestions on improving code + security are welcome.
Good luck!
eelix
You may also want to use mysql_num_rows() [php.net]. Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() [php.net] to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.