PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 14th, 2012, 06:48 AM
BobMallett BobMallett is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 3 BobMallett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 10 sec
Reputation Power: 0
Mysql & other databases - Adding a NULL date value

Hi,

I want to add a Date as NULL in MySQL if a form field is left blank

For example

PHP Code:
if ($New_CAR_Expiry_Date =='')
    {
$New_CAR_Expiry_Date NULL;
}

$query "UPDATE contractors SET " .
"CAR_Insurer='$New_CAR_Insurer', " .
"CAR_Policy_No='$New_CAR_Policy_No', " .
"CAR_Lmt='$New_CAR_Lmt', " .
"CAR_Expiry_Date='$New_CAR_Expiry_Date', " .
"Notes='$New_Notes' WHERE contractor_id ='$contractor_id'"


If I echo my query

UPDATE contractors SET CAR_Insurer='Fred', CAR_Policy_No='1234', CAR_Lmt='0', CAR_Expiry_Date='', Notes='11/7 Email sent requesting insurances. 13/7 Insurances updated' WHERE contractor_id ='46'

it should read

UPDATE contractors SET CAR_Insurer='Fred', CAR_Policy_No='1234', CAR_Lmt='0', CAR_Expiry_Date=NULL, Notes='11/7 Email sent requesting insurances. 13/7 Insurances updated' WHERE contractor_id ='46'

Any ideas what I am doing wrong or how to get the query to execute with the value NULL? At presentt he update adds Car_Expiry_Date as 0000-00-00

Thanks

Reply With Quote
  #2  
Old July 14th, 2012, 07:44 AM
BobMallett BobMallett is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 3 BobMallett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 m 10 sec
Reputation Power: 0
I tried this - it adds NULL but does not add a date!

PHP Code:
if ($New_CAR_Expiry_Date =='')
    {
$New_CAR_Expiry_Date "NULL";
}

$query "UPDATE contractors SET " .
"CAR_Insurer='$New_CAR_Insurer', " .
"CAR_Policy_No='$New_CAR_Policy_No', " .
"CAR_Lmt='$New_CAR_Lmt', " .
"CAR_Expiry_Date=$New_CAR_Expiry_Date, " .
"Notes='$New_Notes' WHERE contractor_id ='$contractor_id'"

Last edited by BobMallett : July 14th, 2012 at 11:32 AM. Reason: Mispellling

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Mysql & other databases - Adding a NULL date value


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap