Jump to content

I am having problem Inserting data. improper function help!


co.ador

Recommended Posts

   <?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

<?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.

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

 

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;

}

 }


 ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.