SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    		$addreview = "INSERT INTO xdb (
    			productname, 
    			category, 
    			reviewer, 
    			reviewshort, 
    			review, 
    			image, 
    			reviewdate, 
    			producturl
    		) VALUES (
    			'$productname',
    			'$category',
    			'$reviewer',
    			'$reviewshort',
    			'$review',
    			'$image',
    			NOW(),
    			'$producturl')";
    
    	$upd = mysql_query($addreview,$db);
    
    		$result = mysql_query($upd,$db);
    		if (!$result) {
    			echo mysql_error();
    			exit;
    		}

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The data is being inserted to the table, even with the error.

    The error is:
    You have an error in your SQL syntax near '1' at line 1.

    My table structure is as follows:

    reviewid int(5) No auto_increment
    productname varchar(50) No
    image varchar(80) No
    reviewshort text No
    review text No
    category varchar(30) No
    reviewer varchar(50) No
    producturl varchar(60) No
    counter int(10) No 0
    reviewdate datetime No 0000-00-00 00:00:00

    The 'No's mean Not Null

    I've tried parring the insert statement down to each seperate field and still get the same error.

    The last thing I tried was hardcoding data in the insert statement, like this:

    $addreview = "INSERT INTO xdb (category) VALUES ('Games')";

    That returns the same error as above.

    Help?

  3. #3
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like:
    $query = "INSERT INTO table SET productname='$productname', image='$image'";


  4. #4
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just made a hybrid UPDATE/INSERT statement. It will not work, for either an update or an insert.



  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually thaty is inaccurate, you can use INSERT into set something = '$something' It is perfectly okay try it for yourself. I think the problem lies that you are trying to run the query twice once
    $upd = mysql_query($addreview,$db);
    here

    and once

    $result = mysql_query($upd,$db);

    here but the second one is invalid because $upd only holds the result identifier from the first query
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Neat, you learn something new every day...

    In my effort to find a problem with the INSERT syntax, I completely overlooked having a second query below the first. Thanks for the second set of eyes



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
  •