An INSERT question
Posted: Mon Mar 10, 2008 10:51 pm
Hey guys... I'm trying to figure out a problem I am having with the correct syntax of an INSERT statement I am trying to construct.
I have a mysql table that holds a name and an optional numeric code.. with the numeric code (ie. 302) being optional. So in my PHP, I have this:
So with this.. as you can see.. $clean['numeric_code'] can either have a value (ie. '302'), or no value at all (NULL).
So here in lies the problem I am having.
Since that is the MySQL table I am trying to insert too... I am getting an error with the following INSERT query I am using if $clean['numeric_code'] is NULL. ie. $clean['numeric_code'] = NULL;
Anyone know a way I can work around this? I need to keep the INSERT query above in tact.. in other words, I can't take the numeric code entry out of the INSERT statement if it is indeed null.
Any help would GREATLY be appreciated. Thanks!
I have a mysql table that holds a name and an optional numeric code.. with the numeric code (ie. 302) being optional. So in my PHP, I have this:
Code: Select all
if (isset($_POST['numeric_code']))
$clean['numeric_code'] = $_POST['numeric_code'];
else
$clean['numeric_code'] = NULL;So here in lies the problem I am having.
Code: Select all
CREATE TABLE names_and_codes (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
persons_name VARCHAR(100) NOT NULL,
numeric_code TINYINT UNSIGNED DEFAULT NULL,
PRIMARY KEY (id)
);Code: Select all
$query = "INSERT INTO names_and_codes (persons_name, numeric_code) VALUES ('{$clean['persons_name']}', {$clean['numeric_code']})";Any help would GREATLY be appreciated. Thanks!