which is supposed to insert the post_type value if it is entered into the input field or NULL otherwise. It inserts the input value (post_type) fine when I enter a value, but when I leave the input field empty, it doesn’t insert anything into the database.
@r937, thank you. The following two queries works:
INSERT INTO posts (post_name, post_type) VALUES ('foobar', 2)
INSERT INTO posts (post_name, post_type) VALUES ('foobar', NULL)
This one doesn’t work:
INSERT INTO posts (post_name, post_type) VALUES ('foobar', 'NULL')
When NULL has quotes, it doesn’t create a new entry in the database. For the record, the post_type is of INT type. Perhaps I need to find a way to assign the NULL value with an IF (?) check inside the query itself, not before the query like I did in the first post.
For clarification, I am not trying to insert text string “NULL”. I am trying to insert the post_type (INT) value if it is provided, and insert NULL if post_type isn’t provided.
[quote=“nayen, post:3, topic:223417, full:true”]Perhaps I need to find a way to assign the NULL value with an IF (?) check inside the query itself, not before the query like I did in the first post.
[/quote]
no, not with sql, with php – php has a perfectly adequate IF capability
just do the test in php, and send the right sql statement to the database