What is wrong with this mysql statement – INSERT INTO … WHERE … OR?

This is my mysql statement but for some reason it isn’t actually working and I can’t figure out why. Thanks in advance!

$ID = $_GET['post'];
$length = $_POST['excerpt_length'];

more code here to connect and select db...

mysql_query("
INSERT INTO wp_posts (excerpt)
VALUES(" . $length . ")
WHERE ID = " . $ID . "
OR post_name LIKE '" . $ID . "%'");

This is for wordpress and I’m making an option to add an excerpt length because as far as I am aware, there isn’t any yet. Thanks!

Read More

Ethan Brouwer

Related posts

Leave a Reply

5 comments

  1. You cant use where in insert into because you are supposed to create a new record, there is no referenced to look for. You must use Update instead.

    mysql_query("
    UPDATE wp_posts 
    SET excerpt = '" . $length . "'
    WHERE ID = '" . $ID . "'
    OR post_name LIKE '" . $ID . "%'");
    
  2. I haven’t checked, but I wouldn’t think you can use an OR-statement in an INSERT-query. Maybe do another query before this one to find out an id to insert to..?