Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post

    INSERT MySQL error

    Hey all,

    came up with a little string here that:
    1. Uploads a text file
    2. Gets data from text file one line at a time
    3. Explodes each line by the TAB delimiter.
    4. Inserts into a mysql database, and outputs.


    It uploads the file, reads the file, outputs the results, but does not insert into mysql. Here is my mysql statement:

    PHP Code:
    while($theData fgets($fh)){

    $part=explode("\t"$theData);

    $sql="INSERT INTO items (customerid, itemname, modelnr, serialnr, condition, location, status, replacement, damage, diagnosis, fstate, labor, parts) VALUES ('$custid', '$part[0]', '$part[1]', '$part[2]', '$part[3]', '$part[4]', '$part[5]', '$part[6]', '$part[7]', '$part[8]', '$part[9]', '$part[10]', '$part[11]')";

    mysql_query($sql$conn) or die mysql_error();
    .... 
    Been messing with it for the past hour and cannot find whats wrong.

    Thx in advance, Erind

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Hmm. You're not intending on using this script over once, are you? The reason I ask is, you're running N query calls in an undetermined loop based on how many lines are in a given file. If that's not a way to kill a server, I don't know what is.

    Anyway, to your problem. Basic troubleshooting steps, blah blah blah. I see you've got mysql_error() there, so the query is obviously valid and not failing, but you say there is nothing in the database when you're done with the script execution? Have you tried to display the value stored in $sql to see that there is anything in the query itself? Or that $part is a valid array and contains what you think it does?

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Is that the exact code you are using? Because or die mysql_error(); gives me a parse error. You have to enclose mysql_error() in parenthesis.

  • #4
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Fumigator View Post
    Is that the exact code you are using? Because or die mysql_error(); gives me a parse error. You have to enclose mysql_error() in parenthesis.
    Good eye. While die() (or exit() for that matter) are not functions, but language constructs, they don't necessarily require the parens. In this case since you're actually passing something into die(), I'm sure that's correct.

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by bdl View Post
    Hmm. You're not intending on using this script over once, are you? The reason I ask is, you're running N query calls in an undetermined loop based on how many lines are in a given file. If that's not a way to kill a server, I don't know what is.

    Anyway, to your problem. Basic troubleshooting steps, blah blah blah. I see you've got mysql_error() there, so the query is obviously valid and not failing, but you say there is nothing in the database when you're done with the script execution? Have you tried to display the value stored in $sql to see that there is anything in the query itself? Or that $part is a valid array and contains what you think it does?

    My files have a set amount of lines. Usually no more than 50-70. Is that not a finite loop?


  •  

    Posting Permissions

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