I run this query to check if cat_name already exists it the mysql database… but it’s show a warning messag.
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs……”
<?php
include("db.php");
if(isset($_POST['cat_name']))
{
$cat_name = mysql_real_escape_string(htmlentities(trim($_POST['cat_name'])));
$err = array();
$ch = mysql_query("SELECT cat_name FROM categories WHERE cat_name = '$cat_name' ");
$num = mysql_num_rows($ch);
if(empty($cat_name))
$err[] = "Category field empty";
elseif(is_numeric($cat_name))
$err[] = "Category name should be string, ex: category name";
elseif($num > 0)
$err[] = "Category name already exits, please choose another name";
else
{
if(strlen($cat_name) < 3)
$err[] = "Category name at least 3 or more
characters";
}
if(!empty($err))
{
foreach($err as $er)
{
echo "<font color=red>$er.</font>";
}
}
else
{
$sql_insert = mysql_query("INSERT INTO categoires VALUES('',
'$cat_name')");
if($sql_insert)
{
echo "Successfully inserted your category name";
}
else
{
echo "Something is wrong to add your cateogory name";
mysql_error();
}
}
}
?>
Any idea?
From the docs:
For
SELECT, SHOW, DESCRIBE, EXPLAINand other statements returningresultset,
mysql_query()returns a resource on success, orFALSEonerror.
mysql_query()will also fail and returnFALSEif the user does nothave permission to access the table(s) referenced by the query.
My best guess is that you have an error in your query.