View Full Version : Ignor certains db_table fields during php/mysql insert

12-07-2010, 03:34 PM
I'm wondering if it is possible to skip certain fields in the mysql table in a sql statement. Here is what I mean:

I have a table that has the following columns:

Suppose I write the following statement:

$mysql_query=("insert db_table (firstname, lastname, phone) VALUES ('$firstname' ,'$lastname', '$phone')");

In the above scenario, I want the statement to insert the above values, and IGNORE the field in "dob" in the database.

Currently, left as is, the dob is check for value and produces the following:

Error: Field 'dob' doesn't have a default value

This may sound a bit unorthodox, but it addresses a critical need at the moment.

I appreciate any thoughts on this!

12-07-2010, 03:36 PM
Set a default on the column value via your SQL cli.

ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT 0;

12-07-2010, 03:48 PM
Thanks for the reply MattF! The things is that 'dob' may or may not already have a value. That field is updated with an other UPDATE statement.

Would adding your suggestion replace that existing value?

12-07-2010, 03:53 PM
Nope. That's merely a default value which is used if you don't supply one in your INSERT. It doesn't have to be zero, btw. That was just for example. You can set any text, NULL etc as the default.

12-07-2010, 04:02 PM
Great! that worked! Thanks!

If the field is a BLOB/TEXT, How can similar concept be achieved?

12-08-2010, 03:26 AM
All issues resolved!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum