Jump to content

Warning: mysql_num_rows() expects parameter 1 to be resource


AeronWarcliffe

Recommended Posts

Hey, this is my first post here, so bear with me: I'm new to PHP, and am trying to make an online store, right now I'm just making an admin inventory management, and so I'm using PHP to link to the database. Before any of this script, I link to the database and all that, so it's not an issue of connection. My issue is I keep getting the following message:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in "inventory_list.php" on line 38

Column count doesn't match value count at row 1

 

There used to be three or four other error messages, but I've been able to work out my mistakes and fix them. Here is my code, starting at Line 27:

<?php
// Parse the form data and add inventory item to the system

if (isset($_POST['product_name'])) {
	$product_name = mysql_real_escape_string($_POST['product_name']);
	$price = mysql_real_escape_string($_POST['price']);
	$category = mysql_real_escape_string($_POST['category']);
	$subcategory = mysql_real_escape_string($_POST['subcategory']);
	$details = mysql_real_escape_string($_POST['details']);
	// See if that product name is an identicle match to another in the system
	$sql = mysql_query("SELECT product_id FROM products WHERE product_name='$product_name' LIMIT 1");
$productMatch = mysql_num_rows($sql); // count the output amount
	if ($productMatch > 0){
		echo 'Sorry, you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>';
		exit();
	}
	// Add this product into the database now
	$sql = mysql_query("INSERT INTO product (product_name, price, category, subcategory, date_added)
		VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error());
	$pid = mysql_insert_id();
	// Place image in the folder
	$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
}
?>

 

The line causing this issue is thus:

$productMatch = mysql_num_rows($sql); // count the output amount

 

Does anyone know how to fix this for me? Thanks

Link to comment
Share on other sites

Your HTML table/form has nothing to do with it.  Your INSERT is incorrect.  Count your fields vs values:

//                                              1        2       3          4            5
$sql = mysql_query("INSERT INTO product (product_name, price, category, subcategory, date_added)
                    VALUES('$product_name','$price','$details','$category','$subcategory',now())") or die (mysql_error());
//                               1             2         3          4             5         6

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.