Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
PHP (MySQL) error : “Warning: mysql_num_rows() expects parameter 1 to be resource”
I am using the following code for uploading a file into the database. I am checking if the file already exists or not. But when i am checking i am getting a warning.
The following is my code.
$filename = $_FILES["uploaded_file"]["name"];
$location = "D:\\TrainingMaterials/";
$path = $location . basename( $_FILES['uploaded_file']['name']);
$data = $mysqli->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
move_uploaded_file( $_FILES["uploaded_file"]["tmp_name"], $location . $_FILES['uploaded_file']['name']);
$q = "select Material_Name,Material_Data from training_material where Material_Name = '$filename' and Material_Data ='$data'";
$rs = $mysqli->multi_query($q);
if (mysql_num_rows($rs) == 0)
{
$result = $mysqli->multi_query("call sp_upload_file('".$id."','" . $filename . "','".$path."','".$data."')");
if ($result)
{
do {
if ($temp_resource = $mysqli->use_result())
{
while ($row = $temp_resource->fetch_array(MYSQLI_ASSOC)) {
array_push($rows, $row);
}
$temp_resource->free_result();
}
} while ($mysqli->next_result());
}
echo "Successfully Uploaded";
}
else
{
echo "Material Already Uploaded";
}
The warning i get is
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in......
Someone help me to find out what i am doing wrong.Thank you in advance
Instead of if(mysql_num_rows($rs) == 0)
, use if($rs->num_rows)
echo $q;
You will get a query execute it in phpmyadmin, I guess the query is wrong.
SELECT Count()
instead retreiveing the actual dataedit: the parameter $data is handled properly by $mysqli->real_escape_string
.
But $filename is also "arbitrary data" as it can be virtually any string the client sends in the http request. So it must be escaped as well.