Help with PHP/mysql site problem

Discussion in 'PHP' started by wrekoniz3, Mar 29, 2009.

Thread Status:
Not open for further replies.
  1. #1
    Recently transferred a site and the database over to one of my servers. For some reason im getting an "error: cant insert data into database"


    I found the string where this is...

    mysql_db_query($database, "INSERT INTO ftont VALUES ('$timestamp','$ip')") or die("Error: Can't insert data into database'");



    Everything else is working good i tested my connection and it worked...but this isnt working for some reason...i dont know. Im confused. someone help me please........
     
    wrekoniz3, Mar 29, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    mysql_db_query($database, "INSERT INTO ftont VALUES (null,'$timestamp','$ip')") or die("Error: Can't insert data into database'");
     
    crivion, Mar 29, 2009 IP
  3. kusal

    kusal Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    kusal, Mar 29, 2009 IP
  4. wrekoniz3

    wrekoniz3 Well-Known Member

    Messages:
    2,232
    Likes Received:
    100
    Best Answers:
    0
    Trophy Points:
    190
    #4
    wrekoniz3, Mar 29, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you want to know the reason for the error condition, you should change the message to something more informative. For example:

    ... or die(mysql_error());
     
    SmallPotatoes, Mar 29, 2009 IP
  6. wrekoniz3

    wrekoniz3 Well-Known Member

    Messages:
    2,232
    Likes Received:
    100
    Best Answers:
    0
    Trophy Points:
    190
    #6
    good idea...


    now i get this....


    Column count doesn't match value count at row 1
     
    wrekoniz3, Mar 29, 2009 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Then there is a discrepancy between what you try to add to the database, and the numbers of columns in the database (table). Is there perhaps another column in the database?
     
    PoPSiCLe, Mar 29, 2009 IP
  8. wrekoniz3

    wrekoniz3 Well-Known Member

    Messages:
    2,232
    Likes Received:
    100
    Best Answers:
    0
    Trophy Points:
    190
    #8
    i dont know... im soo confused.. this is driving me crazy.
     
    wrekoniz3, Mar 29, 2009 IP
  9. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hit me up on messenger (ones in my profile or here) I can help you out. I'll get it all figured out for you.
     
    NatalicWolf, Mar 29, 2009 IP
  10. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ok, now that we have the actual error message it's easy to figure out.

    In an insert statement, you are almost always better off specifying which columns the data go into. For example, if you have one column called "when" and one called "from_where", then you could write your query as:

    ... "insert into ftont (when, from_where) values ('$timestamp', '$ip')" ...

    this way it knows that you want $timestamp to go into 'when', and $ip to go into 'from_where'.

    Otherwise, it will guess. It will put the first value in the first column of your table, the second value in the second column, and so on. And it will fail if the number of values is not exactly identical to the number of columns.
     
    SmallPotatoes, Mar 29, 2009 IP
  11. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This has turned to a bigger issue...We are currently working on it.
     
    NatalicWolf, Mar 30, 2009 IP
Thread Status:
Not open for further replies.