Hi again, A few days ago, I sent in an inquiry (see below) about how to make the date field in mysql read NULL when the corresponding form field was empty. I tried the suggestions I received and the following if statements all seem to still result in a default 0000-00-00 instead of NULL.
/ this enters NULL if event_date is empty if ($event_date == "") $event_date = '\0'; if ($event_date == "") $event_date = "\0"; if ($event_date == "") $event_date = \0; if ($event_date == "") $event_date = NULL; if ($event_date == "") $event_date = '\0'; // here's the insert statement mysql_db_query("$db", "insert into $table (id, approved, author, title, featured, keywords, description, content, type, category, datetime, country, region, event_date) values(null, '$approved', $author, '$title', date_add('$datetime', interval $featured day), '$keywords', '$description', '$content', '$type', '$category', '$datetime', '$country', '$region', '$event_date')"); I'd really appreciate your suggestions and help. I can work around this result, but it's really bugging me now why I can't get the word 'NULL' in the date field when the corresponding form field is empty. thank you, Shawna > ---------- > From: [EMAIL PROTECTED] > Sent: Tuesday, December 4, 2001 5:31 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Simple Question: PHP, MySQL, HTML Form and NULL > > I have added a new column in an existing MYSQL table called "event_date" > - > type: DATE, Null - yes ; default - NULL. > > This database field will be filled if and when the field in the HTML form > is > complete. When I added the new field to MySQL, it automatically assigned > NULL to all the existing records - which is what I wanted it to do. > > I tested the HTML form, and when someone enters a date in the HTML form, > the > date appears correctly in the table field. Perfect. > > Now my question: When the HTML form date field is left blank and the form > is submitted, instead of putting "NULL" in the MySQL event_date field, I > found: 0000-00-00. Is this because the form is submitting an " " to the > database field? > > Is there some kind of if/then statement I should use so that when the > field > is empty, "NULL" will be entered into that table field? > > Thank you, Shawna > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]