Jump to content

conditional insert where clause issue


Recommended Posts



I've been playing around with inserting the name of a file ($additional_upload_nameX)  into the database only if it has been uploaded (it's not mandatory).


When I submit the form, I'm told I have a problem with my WHERE clause. Any idea what I'm doing wrong here?


$query2 = "INSERT INTO uploads (date, upload_name, topic, year, status, keywords, description )" . "VALUES (NOW(), '$additional_upload_nameX', '$topic', '$year',  '$status', '$keywords' , '$description') WHERE $additional_upload_nameX != ''";
//if($query){echo 'data has been placed'}

mysql_query($query2) or die(mysql_error());

Link to comment
Share on other sites

INSERT queries don't have WHERE clauses. Your php code would need to determine when a file has not been uploaded and put a default value into the query statement for the upload_name column or use a query that doesn't have that column listed in it and let the database use the default value you have defined for that column.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.