SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can figured out the problem

    I have this insert statement that inserts 0 in the product_id field instead of the correct number which is set to $product.
    I did echo $product and the variable worked fine.
    is strange because every other variable in the statement works fine except $product
    This is the SQL statement

    PHP Code:
    $sql "INSERT INTO ratings SET ip_address = '" $ip "',
            rating = '" 
    $rating "' ,
        product_id = '" 
    $product "',
            fb_uid = '" 
    $user "',
            title = '" 
    $title "',
            review = '" 
    $review "',
        reviewer = '" 
    $name "',
            date_added = '" 
    $date_added "'";
            
    $result1 mysql_query($sql) or die('Error : ' mysql_error()); 

  2. #2
    SitePoint Member
    Join Date
    May 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    instead of SET you should really be using

    (rating,product_id,etc.) VALUES ("'.$rating.'","'.$product.'",etc.) 

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing product_id is defined as an INT or TINYINT (or similar) column in the database table. Try removing the quotes from around the value in your query:

    PHP Code:
    $sql "INSERT INTO ratings SET ip_address = '" $ip "',
            rating = '" 
    $rating "' ,
        product_id = " 
    $product ",
            fb_uid = '" 
    $user "',
            title = '" 
    $title "',
            review = '" 
    $review "',
        reviewer = '" 
    $name "',
            date_added = '" 
    $date_added "'"
    techsupport21 does speak sense, INSERT ... SET is non-standard SQL syntax so it's sensible to use INSERT... VALUES instead, although this won't cause problems if you're only ever going to be using MySQL.
    Last edited by SJH; May 9, 2009 at 11:48.


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
  •