Possible Duplicate:
Best way to stop SQL Injection in PHP
supplied argument is not a valid MySQL result resource
php/mysql account activation
Can't figure this out for the life of me...
Basically I just want to check if a record exists and if it doesn't, do something and if it does, do something else. Can't get it to work with this code I've written.
First of all, the error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in claimreview.php on line 7
Here is my db connection (which is working fine as it doesn't give any errors)
dbconn.php
<?
// e.g. dbconn('localhost','your_database','your_login','your_pass');
$db = dbconn('localhost','db','login','pass');
// No need to edit below this line.
function dbconn($server,$database,$user,$pass){
// Connect and select database.
$db = mysql_connect($server,$user,$pass);
$db_select = mysql_select_db($database,$db);
return $db;
}
?>
And here is my script which takes in an email (which I am echoing to make sure it is receiving the email, and it is)
<?php
include('functions/dbconn.php');
$email = $_POST["email"];
$sql = "SELECT * FROM reviewers WHERE email = '$email'";
echo $sql;
$result = mysql_query($sql);
$num = mysql_num_rows($result); //LINE 7
if ($num > 0) {
echo "Found record";
}
else
{
echo "Didn't find record </br>";
}
echo $num;
echo $email;
?>
It is echoing the SQL also which looks like this:
SELECT * FROM reviewers WHERE email = 'email-from-form-here'