Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\M\admin\page_functions\news_list.php on line 49
$productCount = mysql_num_rows($sql);
can you please help with this problem?
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
if (isset($_GET['deleteid'])) {
echo 'Are you sure you want to delete the product ' . $_GET['deleteid'] . '? <a href="inventory_list.php?yesdelete=' . $_GET['deleteid'] . '">yes</a> | <a href="inventory_list.php">Nej</a>';
exit();
}
if (isset($_GET['yesdelete'])) {
$id_to_delete = $_GET['yesdelete'];
$sql = mysql_query("DELETE FROM products WHERE id='$id_to_delete' LIMIT 1") or die (mysql_error());
$pictodelete = ("../store_images/$id_to_delete.jpg");
if (file_exists($pictodelete)) {
unlink($pictodelete);
}
header("location: store_list.php");
exit();
}
?>
<?php
if (isset($_POST['product_name'])) {
$product_name = mysql_real_escape_string($_POST['product_name']);
$price = mysql_real_escape_string($_POST['price']);
$product_code = mysql_real_escape_string($_POST['product_code']);
$type = mysql_real_escape_string($_POST['type']);
$category = mysql_real_escape_string($_POST['category']);
$time = mysql_real_escape_string($_POST['time']);
$details = mysql_real_escape_string($_POST['details']);
$sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql);
if ($productMatch > 0) {
echo 'There is already a product with that name, <a href="store_list.php">click</a>';
exit();
}
$sql = mysql_query("INSERT INTO products (product_name, price, product_code, type, details, category, time, date_added)
VALUES('$product_name','$price', '$product_code', '$type','$details','$category','$time',now())") or die (mysql_error());
$pid = mysql_insert_id();
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../store_images/$newname");
header("location: store_list.php");
exit();
}
?>
<?php
$product_list = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
$productCount = mysql_num_rows($sql);
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%d %b, %Y", strtotime($row["date_added"]));
$product_list .= "<strong>$product_name</strong> - $price dollar. - <em>added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />";
}
} else {
$product_list = "You have no items in your store yet";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="da-DK"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin</title>
<link href="../style.css" rel="stylesheet" type="text/css">
<link href="src/facebox.css" media="screen" rel="stylesheet" type="text/css" />
<script src="lib/jquery.js" type="text/javascript"></script>
<script src="src/facebox.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('a[rel*=facebox]').facebox({
loadingImage : 'src/loading.gif',
closeImage : 'src/closelabel.png'
})
})
</script>
</tr>
<tr id="bodyrow">
<td width="59%" id="middle">
<div class="post-2 page type-page status-publish hentry post odd" id="post-2">
<div class="post-headline">
<a href="index.php"><h1>Admin</h1></a></div>
<div id="pageContent"><br />
<div align="right" style="margin-right:32px;"><a href="new_product.php#inventoryForm">+ add new product</a></div>
<div align="left" style="margin-left:24px;">
<h2>liste</h2>
<?php echo $product_list; ?>
</div>