SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with simple INSERT

    Having a problem and I'm sure its something simple I'm just not seeing. Code makes it to and past my query and prints out affected rows with no errors.
    Problem: values are not in database but variables will print out from the code so I know they are not empty..

    foreach ($response->product as $product) {

    $sku=$product->sku;
    $categorie = "camping";
    $ti=$product->ti;
    $fdesc=mysql_real_escape_string($product->fdesc);
    $list=$product->list;
    $small=$product->sku . "SM.gif";
    $large=$product->sku . ".gif";
    $qty=$product->qty;
    $mfg=$product->mfg;
    $wt=$product->wt;

    mysql_query("INSERT INTO products(productID,category,productTitle,description,list,smallPic,bigPic,stock,manufacturer,weight) VALUES ('$sku','$categorie','$ti','$fdesc','$list','$small','$large','$qty','$mfg','$wt'");

    printf ("Updated records: %d\n", mysql_affected_rows());

    echo $product->sku . " - " . $sku . "-" . $wt . "<br>";

    }

    Maybe just need some fresh eyes.
    Thanks

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have you tried printing out the query you're executing and looking at it?

    PHP Code:
    $query "INSERT INTO products(productID,category,productTitle,description,list,smallPic,bigPic,stoc k,manufacturer,weight) VALUES ('$sku','$categorie','$ti','$fdesc','$list','$small','$large','$qty','$mfg','$ wt'";

    echo 
    $query;

    mysql_query($query); 
    At least two of your mistakes would become apparent... "stoc k" as a column name, "$ wt" as a value...

    While it probably wouldn't cause a problem, are all these columns of type VARCHAR/TEXT? Numeric values shouldn't be enclosed in quotes as all your values are.

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan, I'll try to print the query. The spaces were added by the forum post and I originally didn't have the quotes. Just was trying everything I could think of to troubleshoot it. I'll go give your ideas a shot.
    Thanks

  4. #4
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query shows all data. Should be succesful but still hasn't been inserted into db???? Shows 28 rows affected. How wierd. I've added to the db manually but I'm trying to import an XML file. Everything works to here.
    Any other thoughts?
    Thanks

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also changed quotes on numeric columns.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    28 rows affected should be a hint! Insert should produce only one row.

    You're missing the closing ) at the end of the query


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
  •