Duplicate Insert

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Duplicate Insert

Post by pauldr »

I have read a couple of posts on data being inserted twice, but everyone is asking for the code. I am having the same issue. Here is my code:

Code: Select all

<?php   
require('../include/connect.php');
 
$category = $_POST[category];
$short_desc = htmlspecialchars($_POST[short_desc]);
$part_no = htmlspecialchars($_POST[part_no]);
$vendor = htmlspecialchars($_POST[vendor]);
$unit_price = $_POST[unit_price];
$long_desc = htmlspecialchars($_POST[long_desc]);
$max_qty = $_POST[max_qty];
$qty = $_POST[qty];
 
$sql="INSERT INTO `item` 
            (`category_id`,
             `short_desc`,
             `part_no`,
             `vendor`,
             `unit_price`,
             `long_desc`,
             `max_qty`,
             `qty`) 
        VALUES 
            ('$category',
             '$short_desc',
             '$part_no',
             '$vendor',
             '$unit_price',
             '$long_desc',
             '$max_qty',
             '$qty')";
 
mysql_query($sql);
 
if (!mysql_query($sql))
  {
  die('Error: ' . mysql_errno() . ", " . mysql_error());
  }
 
mysql_close($con);  
  
header("Location: item.php")  
  
?>
Can someone let me know why this may be happening?

Thank you,
Paul
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: Duplicate Insert

Post by it2051229 »

here it is:

the first query is this

Code: Select all

 
blah
blah 
blah
mysql_query($sql); <------
 
the second query is this

Code: Select all

 
blah
blah
if (!mysql_query($sql)) <------
{
     blah
     blah
    blah
}
 
Post Reply