co.ador Posted April 5, 2011 Share Posted April 5, 2011 <?php $sqlinsert = mysql_query( "INSERT INTO costumers (firstname,lastname,birthdate,product_name,price,details,category,subcategory,city,state,zipcode,country) VALUES ('$fname','$lname','$birthday','$itemname','$price','$details','$category','$subcategory','$city','$state','$zipcode','$country',)" ); // line 19 $insertCount = mysql_num_rows($sqlinsert); if ($insertCount>0 ) { $newrecord = "$itemname was inserted"; } } ?> Having problems at line 19 mysql_num_rows functions is not working it seems it is not suitable for an insert. What function I could use in there. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /public_html/InsertForm.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/232767-i-am-having-problem-inserting-data-improper-function-help/ Share on other sites More sharing options...
co.ador Posted April 5, 2011 Author Share Posted April 5, 2011 <?php $sqlinsert = mysql_query( "INSERT INTO costumers (firstname,lastname,birthdate,product_name,price,details,category,subcategory,city,state,zipcode,country) VALUES ('$fname','$lname','$birthday','$itemname','$price','$details','$category','$subcategory','$city','$state','$zipcode','$country',)"); // line 19 $insertCount = mysql_num_rows($sqlinsert); if 0($insertCount>0 ) { $newrecord = "$itemname was inserted"; } ?> sorry about that mess in the first post. Quote Link to comment https://forums.phpfreaks.com/topic/232767-i-am-having-problem-inserting-data-improper-function-help/#findComment-1197267 Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2011 Share Posted April 5, 2011 mysql_num_rows() expects a result resource because it is used with SELECT/SHOW queries. An INSERT query only returns a true/false value. To find out if an INSERT query actually inserted a row, after you check that the query executed without any errors, you would use mysql_affected_rows Quote Link to comment https://forums.phpfreaks.com/topic/232767-i-am-having-problem-inserting-data-improper-function-help/#findComment-1197269 Share on other sites More sharing options...
Pikachu2000 Posted April 5, 2011 Share Posted April 5, 2011 I fixed it up for you anyhow . . . Quote Link to comment https://forums.phpfreaks.com/topic/232767-i-am-having-problem-inserting-data-improper-function-help/#findComment-1197270 Share on other sites More sharing options...
co.ador Posted April 5, 2011 Author Share Posted April 5, 2011 Thank you Pikachu. PFM I have set it to true and if set to true it will display "item1 was inserted." Now the code below seems to submit the form, it is set to true and display the "item1 was inserted" message but when I go in the database table costumers I don't find any record of the Insert. <?php $sqlinsert = mysql_query( "INSERT INTO costumers (firstname,lastname,birthdate,product_name,price,details,category,subcategory,city,state,zipcode,country) VALUES ('$fname','$lname','$birthday','$itemname','$price','$details','$category','$subcategory','$city','$state','$zipcode','$country',)" ); $newrecord = '' . $itemname . ' was inserted' ; if ($sqlinsert=true ) { echo $newrecord; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232767-i-am-having-problem-inserting-data-improper-function-help/#findComment-1197290 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.