Jump to content

Duplicate entry '0' for key 1?? Trying to send details to DB


mikebyrne

Recommended Posts

Im trying to create a form to allow users to enter new products to the database but when the form loads I get an Duplicate entry '0' for key 1 error

 

my code is:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>e-commerce admin page sample |item</title>
<link href="../Admin_files/admin.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript" src="../includes/wrapper.js"></script>
</head>
<body>
<div id="Box">
  <div id="logoBox"><a href="http://www.btrax.com/" target="_blank"><img src="../Admin_files/logo.gif" width="51" height="125" border="0" /></a></div>
  <div id="contentBox">
<form action="add.php" onsubmit="return valid()" method="post">
<?PHP
require_once("adminconnect.php");

$tbl_name="product";

$sql="INSERT INTO `$tbl_name` (`ProductNo`, `ProductName`, `Description`, `Price`) VALUES ('$ProductNo', '$ProductName', '$Description', '$Price')";
$result = mysql_query($sql) or die (mysql_error());
?>


      <!-- logo start -->
      <div id="container">
        <div class="padTop28">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>

      <div class="clr">
        <!-- -->
      </div>
      <!-- logo finish -->
      <!-- menu start -->
      <div id="container">
			<div id="menu1">
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/start.php" class="black">Order</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/sales.php" class="black">Sales</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/list.php" class="black">Edit item</a></div>
		<div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
		<div id="menu_text_off"><a href="../admin_files/postage.php" class="black">Postage fee</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_off"><!-- --></div>
            <div id="menu_text_off"><a href="../admin_files/adminreg.php" class="black">Add User</a></div>
            <div id="menu_space1"><!-- --></div>
		<div id="menu_on"><!-- --></div>
            <div id="menu_text_on"><a href="../admin_files/add.php" class="black_on">Add Product</a></div>
		<div id="menu_space1"><!-- --></div>
	</div>
          <!-- -->
         <!-- Double Space undernath CD -->
          <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
        <div class="clr"><!-- --></div>		<div class="clr"><!-- --></div>
	<div class="padTop5"><!-- --></div>
	<div class="clr"><!-- --></div>
      <!-- menu finish -->
      <!-- top start -->
      <div id="container">
        <div id="line">
          <!-- -->

        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>
      <div id="containerBg1">
        <div class="padTop15">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <div id="titleText">EDIT ITEM</div>
        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop15">

          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>

      <!-- top finish -->
      <!-- data title start -->
      <div id="containerBg2">
        <div class="padTop2">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>

        <div class="titleBox">
          <table width="850" border="0" cellspacing="0" cellpadding="0">
            <tr align="left">
              <td width="33"> </td>
              <td width="290" align="left">IMAGE</td>
              <td width="527">DETAIL</td>
            </tr>
          </table>

        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>
      <!-- data title finish -->

      <!-- 1px space start -->
      <div id="containerBg1">
        <div class="padTop1">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>

      <div class="clr">
        <!-- -->
      </div>
      <!-- 1px space finish -->
      <!-- data top start -->
      <div id="containerBg3">
        <div class="padTop1">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
      </div>
      <div class="clr">
        <!-- -->
      </div>
      <!-- data top finish -->
      <!-- data content start -->



      <div id="containerBg4">
      <div class="padTop15">
        <!-- -->
      </div>
      <div class="clr">
        <!-- -->
      </div>
      <div class="padTop1">
        <!-- data Left start -->

        <div class="editLeft">
          <!-- picture1 start -->
          <div class="editLeftBox">PICTURE 1:</div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="padTop5">
            <!-- -->

          </div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="editLeftBox"><img src="<?php echo $row['Image'];?>" alt="pic1" width="150" height="200" /></div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="padTop5">

            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="editLeftBox">
            <input type="file" name="uploadfile" class="newsUpFile">
          </div>
          <div class="clr">

            <!-- -->
          </div>
          <!-- picture1 finish -->
          <div class="padTop50">
            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>

          <!-- picture2 start -->
          <div class="editLeftBox">PICTURE 2:</div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="padTop5">
            <!-- -->
          </div>

          <div class="clr">
            <!-- -->
          </div>
          <div class="editLeftBox"><img src="<?php echo $row['Image2'];?>" alt="pic1" width="150" height="200" /></div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="padTop5">
            <!-- -->

          </div>
          <div class="clr">
            <!-- -->
          </div>
          <div class="editLeftBox">
            <input type="file" name="uploadfile" class="newsUpFile">
          </div>
          <div class="clr">
            <!-- -->

          </div>
          <!-- picture2 finish -->
        </div>
        <!-- data Left finish -->
        <!-- data Right start -->
        <div class="editRight">
          <!-- dat start -->
          <div class="editRightBox">
            <div class="editRightText">Product No:</div>

            <div class="editRightForm">
            <!--MAKES PRODUCT NO READ ONLY-->
            <input type="text" class="itemEditForm02" name="ProductNo" value="<?php echo $row['ProductNo'];?>" readonly="readonly" /> 
            </div>
            <div class="clr">
              <!-- -->
            </div>
          </div>
          <div class="clr">
            <!-- -->

          </div>
          <!-- data finish -->
          <div class="padTop3">
            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>
          <!-- dat start -->

          <div class="editRightBox">
            <div class="editRightText">Product Name:</div>
            <div class="editRightForm">
              <input name="0" type="text" class="itemEditForm02" name="ProductName" value="<?php echo $row['ProductName'];?>" />
            </div>
            <div class="clr">
              <!-- -->
            </div>

          </div>
          <div class="clr">
            <!-- -->
          </div>
          <!-- data finish -->
          <div class="padTop3">
            <!-- -->
          </div>
          <div class="clr">

            <!-- -->
          </div>
          <!-- dat start -->
          <div class="editRightBox">
            <div class="editRightText">Description:</div>
            <div class="editRightForm">
              <textarea type="text" class="itemEditForm03" name="something" ><?php echo $row['Description'];?></textarea>
            </div>

            <div class="clr">
              <!-- -->
            </div>
          </div>
          <div class="clr">
            <!-- -->
          </div>
          <!-- data finish -->
          <div class="padTop3">

            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>
          <!-- dat start -->
          <div class="editRightBox">
            <div class="editRightText">Remarks:</div>

            <div class="editRightForm">
              <input type="text" class="itemEditForm02" name="0" value="" />
            </div>
            <div class="clr">
              <!-- -->
            </div>
          </div>
          <div class="clr">
            <!-- -->

          </div>
          <!-- data finish -->
          <div class="padTop3">
            <!-- -->
          </div>
          <div class="clr">
            <!-- -->
          </div>
          <!-- dat start -->

          <div class="editRightBox">
            <div class="editRightText">Price:</div>
            <div class="editRightForm">
              <div class="editItemPrice1">€</div>
              <div class="editItemPrice2">
                <input type="text" class="itemEditForm04" name="0" value="<?php echo $row['Price'];?>" />
              </div>
              <div class="clr">

                <!-- -->
              </div>
              <div class="clr">
                <!-- -->
              </div>
            </div>
            <div class="clr">
              <!-- -->
            </div>


            <!-- data finish -->
            <div class="padTop3">
              <!-- -->
            </div>
            <div class="clr">
              <!-- -->
            </div>
            <!-- dat start -->
            <div class="editRightBox">

              <div class="editRightText">Sale:</div>
              <div class="editRightForm">
                <div class="editRadioLink1">
                  <input name="link" type="radio" value="yes" />
                </div>
                <div class="editRadioLink2">Yes</div>
                <div class="editRadioLink3">
                  <input name="link" type="radio" value="no" checked="checked" />

                </div>
                <div class="editRadioLink4">No   -   sale price: € </div>
                <div class="editRadioLink5">
                  <input type="text" class="newsEditForm02" name="0" value="0" />
                </div>
                <div class="clr">
                  <!-- -->

                </div>
              </div>
              <div class="clr">
                <!-- -->
              </div>
            </div>
            <div class="clr">
              <!-- -->
            </div>

            <!-- data finish -->
            <div class="padTop3">

              <!-- -->
            </div>
            <div class="clr">
              <!-- -->
            </div>
            <!-- dat start -->
            <div class="editRightBox">

              <div class="editRightText">Display:</div>
              <div class="editRightForm">
                <div class="editRadio1">
                  <input name="display" type="radio" value="yes" checked="checked" />
                </div>
                <div class="editRadio2">show</div>
                <div class="editRadio3">
                  <input name="display" type="radio" value="no" />

                </div>
                <div class="editRadio4">hide</div>
              </div>
              <div class="clr">
                <!-- -->
              </div>
            </div>
            <div class="clr">

              <!-- -->
            </div>
            <!-- data finish -->
            <div class="padTop75">
              <!-- -->
            </div>
            <div class="clr">
              <!-- -->
            </div>

          

          </div>
          <!-- data Right finish -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop11">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <div id="dottedIn">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>

        <!-- data finish -->
        <!-- btn start -->
        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop16">
          <!-- -->
        </div>
        <div class="clr">

          <!-- -->
        </div>
        <div id="btn">
          <input id="btnL" type="submit" name="Submit" value="" />
          <div id="btnSpace">
            <!-- -->
          </div>
          <div id="btnR"><img src="../Admin_files/btn_clear.gif" width="73" height="23" /></div>
          <div class="clr">

            <!-- -->
          </div>
        </div>
        <div class="clr">
          <!-- -->
        </div>
        <div class="padTop16">
          <!-- -->
        </div>

        <div class="clr">
          <!-- -->
        </div>
        <!-- btn finish -->
      </div>
      <div class="clr">
        <!-- -->
      </div>

      <!-- data content finish -->

      <!-- data btm start -->
      <div id="containerBg3">
        <div class="padTop1">
          <!-- -->
        </div>
        <div class="clr">
          <!-- -->
        </div>
      </div>

      <div class="clr">
        <!-- -->
      </div>
      <!-- data btm finish -->
      
    </form>
  </div>
  <!-- btm start -->
  <div id="containerBg1">
    <div class="padTop15">

      <!-- -->
    </div>
    <div class="clr">
      <!-- -->
    </div>
  </div>
  <div class="clr">
    <!-- -->
  </div>

  <div id="container">
    <div id="line">
      <!-- -->
    </div>
  </div>
  <div class="clr">
    <!-- -->
  </div>
  <div class="padTop16">

    <!-- -->
  </div>
  <div class="clr">
    <!-- -->
  </div>
  <!-- btm finish -->
</div>
</body>
</html>

 

Link to comment
Share on other sites

Where are you initializing these variables exactly? The problem is that they are not initialized correctly.

 

$sql="INSERT INTO `$tbl_name` (`ProductNo`, `ProductName`, `Description`, `Price`) VALUES ('$ProductNo', '$ProductName', '$Description', '$Price')";

 

Orio.

Link to comment
Share on other sites

Ive initalized them but still getting the error

 

 

<form action="add.php" onsubmit="return valid()" method="post">
<?PHP

require_once("adminconnect.php");

$ProductNo = mysql_real_escape_string(trim($_POST['ProductNo']));
$ProductName = mysql_real_escape_string(trim($_POST['ProductName']));
$Description = mysql_real_escape_string(trim($_POST['Description']));
$Price = mysql_real_escape_string(trim($_POST['Price']));

$tbl_name="Product";

$sql="INSERT INTO `$tbl_name` (`ProductNo`, `ProductName`, `Description`, `Price`) VALUES ('$ProductNo', '$ProductName', '$Description', '$Price')";
$result = mysql_query($sql) or die (mysql_error());
?>

Link to comment
Share on other sites

the sql for the table is

 

CREATE TABLE `product` (

  `Producttype` varchar(4) collate latin1_general_ci default NULL,

  `ProductNo` decimal(7,0) NOT NULL default '0',

  `ProductName` varchar(80) collate latin1_general_ci default NULL,

  `Stockamount` decimal(5,0) default NULL,

  `Display` varchar(3) collate latin1_general_ci default NULL,

  `Description` varchar(10000) collate latin1_general_ci default NULL,

  `Price` decimal(6,2) default NULL,

  `Image` varchar(50) collate latin1_general_ci default NULL,

  `Image2` varchar(50) collate latin1_general_ci default NULL,

  PRIMARY KEY  (`ProductNo`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

 

Link to comment
Share on other sites

Ok I've deleted the table and set it up again

 

CREATE TABLE `product` (

  `Producttype` varchar(4) collate latin1_general_ci default NULL,

  `ProductName` varchar(80) collate latin1_general_ci default NULL,

  `ProductNo` decimal(50,0) NOT NULL,

  `Stockamount` decimal(5,0) default NULL,

  `Display` decimal(3,0) default NULL,

  `Description` varchar(1000) collate latin1_general_ci default NULL,

  `Price` decimal(6,2) default NULL,

  `Image` varchar(50) collate latin1_general_ci default NULL,

  `Imgae2` varchar(50) collate latin1_general_ci default NULL,

  PRIMARY KEY  (`ProductNo`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

 

But the only details to pass to the DB is ProductNo

Link to comment
Share on other sites

ok ugh make the productnu autonumber auto increment. that way it will increase every time something is added to the database. that way if u need to u can call something by the id and get the info from that table

 

CREATE TABLE `product` (
  `Producttype` varchar(4) collate latin1_general_ci default NULL,
  `ProductName` varchar(80) collate latin1_general_ci default NULL,
  `ProductNo` decimal(50,0) NOT NULL autoincrement,
  `Stockamount` decimal(5,0) default NULL,
  `Display` decimal(3,0) default NULL,
  `Description` varchar(1000) collate latin1_general_ci default NULL,
  `Price` decimal(6,2) default NULL,
  `Image` varchar(50) collate latin1_general_ci default NULL,
  `Imgae2` varchar(50) collate latin1_general_ci default NULL,
  PRIMARY KEY  (`ProductNo`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

Link to comment
Share on other sites

Im getting an error on the autoincrement line in the SQl, I've tried different ways to phrase it but still getting an error on the line: `ProductNo` decimal(50,0) NOT NULL DEFAULT AUTOINCREMENT,

 

CREATE TABLE `product` (

  `Producttype` varchar(4) collate latin1_general_ci default NULL,

  `ProductName` varchar(80) collate latin1_general_ci default NULL,

  `ProductNo` decimal(50,0) NOT NULL DEFAULT AUTOINCREMENT,

  `Stockamount` decimal(5,0) default NULL,

  `Display` decimal(3,0) default NULL,

  `Description` varchar(1000) collate latin1_general_ci default NULL,

  `Price` decimal(6,2) default NULL,

  `Image` varchar(50) collate latin1_general_ci default NULL,

  `Imgae2` varchar(50) collate latin1_general_ci default NULL,

  PRIMARY KEY  (`ProductNo`)

) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

Link to comment
Share on other sites

Ok Ive finally got the DB sorted but the values are still not getting passed to my DB.

 

My db is line that was changed is:

 

`ProductNo` double(50,0) NOT NULL auto_increment,

 

The details not getting passed across when I press the button are:

 

ProductName

Description

Price

 

If I could get ONE to pass across Im can get the rest of the code to work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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