I have been troubleshooting this piece of code for quite some time and have come up against a brick wall. I copied code that works for inserting data into a different table - all I did was change the variables for the new table!
The product has a lot more fields but I've taken them out for troubleshooting purposes to simplify the script. The code included below still not inserting data.
Printing out SQL to screen and all looks fine. Just seems to shit itself at the $result = mysql_query ($query) bit. Nothing is inserted into the database and the success line doesn't print.
Have checked database connection is fine as well....any ideas? Many thanks to anyone who can help.
HERE"S THE CODE:
<?php
include ("../include/staff_login_header.php");
include ("../include/db_connect.php");
$product_code=$POST['product_code'];
$product_name=$POST['product_name'];
if (!$product_code || !$product_name )
{
echo 'You have not entered completed all required details. Please go back and try again.';
exit;
}
$product_code= trim($product_code);
$product_name= trim($product_name);
if (!get_magic_quotes_gpc())
{
$product_code = addslashes($product_code);
$product_name = addslashes($product_name);
}
$query = "insert into product values ('".$product_code."', '".$product_name."')";
echo "<h1>".$query."</h1>";
$result = mysql_query($query);
if($result)
echo mysql_affected_rows()." new product has been successfully added. ";
?>