Jump to content

mysql INSERT?


mat3000000
 Share

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
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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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