SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Orlando, FL
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Double entry problem when using INSERT (MySQL)

    When I insert the info into a table, it enters it twice. It even increments the PRODUCT_ID for each entry. I don't know why it's being entered twice. It's not an error in my code, look:
    PHP Code:
    //Test to see if the user added a new product, then insert data
    if ($_POST['addproduct'] == "yes") {
        
    $new_SKU $_POST['SKU'];
        
    $new_desc $_POST['description'];
        
    $new_summary $_POST['summary'];
        
    $new_icon $_POST['icon_img_link'];
        
    $new_small $_POST['small_img_link'];
        
    $new_large $_POST['large_img_link'];
        
        
    $username="*******";
        
    $password="***********";
        
    $database="******";
        
        
    mysql_connect(localhost,$username,$password);
        @
    mysql_select_db($database) or die("Unable to select database");
        
        
    $add_product_qry "INSERT INTO Products VALUES ('','$new_SKU','$new_desc','$new_summary','$new_icon','$new_small','$new_large','')";
        
    mysql_query($add_product_qry);    
        
        if (!
    mysql_query($add_product_qry))
            die(
    'This is the error: ' mysql_error());
        
        
    mysql_close();

    This code is not part of a while loop, and there are no similar statements in my code! think it might have to do with how the table is set up because for some tables, it works correctly. HELP!!!!!

  2. #2
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you reloading the page by any chance (or using a redirect that may be hitting this page again before continuing on)?

  3. #3
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    696
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    The function mysql_query is invoked twice. Remove the first occurrance.

  4. #4
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Orlando, FL
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AWESOME!!!!!!! I thought that it would just read that SQL statement for an error, I didn't know that it was running the Query twice. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •