Jump to content

mysql INSERT?


mat3000000

Recommended Posts

I just keep getting INSERT FAIL, but this script used to work. Can anyone see the problem?


        $name = str_replace('"','"',$_POST['name']);
$new = $_POST['new'];
$cat = $_POST['cat'];
$desc = $_POST['desc'];
$desc = str_replace("\n", "<br />",$desc);
$desc = str_replace('"','"',$desc);
$price = $_POST['price'];
$stock = $_POST['stock'];
$code = $_POST['code'];


if (strpos($price,'£')) {die('You must not include the £ sign in the price field');}
if($name==''||$price=='')die("Name and Price need to be filled in.");


mysql_query("INSERT INTO `stock` ( `id` , `category`,  `name` ,  `description` ,  `new` ,  `price` ,  `stock` ,  `customer` ,  `ProductCode` ) VALUES ('', '$cat', '$name', '$desc', '$new', '$price', '$stock', '0', '$code')")or die("INSERT FAIL");

Link to comment
https://forums.phpfreaks.com/topic/245822-mysql-insert/
Share on other sites

That indicates you have a column defined with a unique index. You are providing the value "127" for that column, but there is already a row with that value in that column.

 

It looks like your "id" column is defined as AUTO INCREMENT. Is that column also defined as TINYINT? A tinyint is one byte which can range from -128 to +127. If you make it UNSIGNED you could go from 0 to 255. You may need to make that column a larger integer type and, for AUTO INCREMENT, you may as well use UNSIGNED since the system will never assign a negative number you may as well use the extra values allowed.

Link to comment
https://forums.phpfreaks.com/topic/245822-mysql-insert/#findComment-1262637
Share on other sites

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.