INSERT being broken and i dont know why

Discussion in 'Databases' started by Dirty-Rockstar, Sep 23, 2007.

  1. #1
    inventoryID (this is key)
    inventoryitemID
    inventoryuserID
    inventoryquantity

    
    <?
    include('sidebar.php');
    if($_SESSION[loggedin])
    {
    Print "logged in and <br>";
    $insert= "INSERT INTO inventory (inventoryitemID, inventoryuserID, inventoryquantity)VALUES('1', '$id', '2')" or die(mysql_error());
    if(mysql_query($insert))
    {
    print "worked and id is 
    <br><br><br> $id";
    }
    else{
    print "nope";
    }
    }
    ?>
    
    PHP:
    prints $id and the else. i have no idea why it wont insert O_O code seems ok..
     
    Dirty-Rockstar, Sep 23, 2007 IP
  2. RaginBajin

    RaginBajin Peon

    Messages:
    87
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's the error that you receive?
     
    RaginBajin, Sep 23, 2007 IP
  3. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Add a Line

    Print $insert;

    and run the value of $insert through phpmyadmin.
    Does it insert a row through phpmyadmin?
     
    Kuldeep1952, Sep 23, 2007 IP
  4. Dirty-Rockstar

    Dirty-Rockstar Guest

    Messages:
    252
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    print is

    INSERT INTO inventory (inventoryitemID, inventoryuserID, inventoryquantity)VALUES('1', '1', '2')

    ID 1 is me = )
    i am using phpmyadmin, It is a cpanel account. there is no error, im connected. im too tired to deal with this now. its annoying the crap out of me
     
    Dirty-Rockstar, Sep 23, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    So when you used phpMyAdmin, it worked?

    Also, these 2 lines:
    $insert= "INSERT INTO inventory (inventoryitemID, inventoryuserID, inventoryquantity)VALUES('1', '$id', '2')" or die(mysql_error());
    if(mysql_query($insert))
    PHP:
    should be:
    $insert= "INSERT INTO inventory (inventoryitemID, inventoryuserID, inventoryquantity)VALUES('1', '$id', '2')";
    mysql_query($insert) or die(mysql_error());
    echo 'success';
    PHP:
     
    krt, Sep 23, 2007 IP
  6. james_r

    james_r Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    personally, when i'm debugging or trying to find a problem i find it helpful to do:

    
    $insert= "INSERT INTO inventory (inventoryitemID, inventoryuserID, inventoryquantity)VALUES('1', '$id', '2')";
    mysql_query($insert) or die($insert . '<br><br>' . mysql_error());
    echo 'success';
    
    PHP:

    makes it nice and easy to read the actual SQL and see if I can figure out exactly where the error is :) sometimes the error alone just isn't enough!
     
    james_r, Oct 5, 2007 IP