AeronWarcliffe Posted April 4, 2012 Share Posted April 4, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
Muddy_Funster Posted April 4, 2012 Share Posted April 4, 2012 change this: $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0){ to this: if(mysql_num_rows($sql)){ Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334287 Share on other sites More sharing options...
AeronWarcliffe Posted April 4, 2012 Author Share Posted April 4, 2012 I fixed the first issue, was a simple problem of mis-naming the sql table, but thanks anyway... I am still, however, getting: Column count doesn't match value count at row 1. what does that mean? Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334288 Share on other sites More sharing options...
Muddy_Funster Posted April 4, 2012 Share Posted April 4, 2012 it means you trying to push 6 valies into 5 fields. You only list 5 fields in your insert, and have 6 values, you missed out the details column name. Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334290 Share on other sites More sharing options...
AeronWarcliffe Posted April 4, 2012 Author Share Posted April 4, 2012 Thanks, I'll stick something in and hope for the best... Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334291 Share on other sites More sharing options...
AeronWarcliffe Posted April 4, 2012 Author Share Posted April 4, 2012 Can you explain it again? I'm not sure what I've done wrong Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334295 Share on other sites More sharing options...
kicken Posted April 4, 2012 Share Posted April 4, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334300 Share on other sites More sharing options...
AeronWarcliffe Posted April 4, 2012 Author Share Posted April 4, 2012 OOHHHHH!!!! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/260336-warning-mysql_num_rows-expects-parameter-1-to-be-resource/#findComment-1334301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.