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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old July 19th, 2004, 10:49 AM
busboy busboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 busboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to busboy
How do I INSERT a NULL using PHP?

I have a very simple page that pulls data from the database and populates <input type=text> fields. This way I can make modifications to the data. Sometimes the phone number people provide is bogus, so I remove the numbers from the field. Howeve, once I click my "submit" button, the phone field in mySQL database is empty, but it's not a NULL value. How do I set my PHP code to insert a NULL if the text field is empty?

Thank you.

Reply With Quote
  #2  
Old July 19th, 2004, 12:38 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Just add validation on the phone number field: if $var=="", $var="NULL". Of course, you then also need to handle not adding quotes around the NULL in your query, but that's no biggie.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #3  
Old July 19th, 2004, 12:47 PM
busboy busboy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 5 busboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to busboy
Would this work?

Thanks for your comments. So if $phone = "NULL" would my query look like this?

update communications set phone = $phone where cID = 200


Thanks.

Reply With Quote
  #4  
Old July 19th, 2004, 02:22 PM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
no... you woukd need to write
>>phone = '$phone' where id<<

- Pheifel

Reply With Quote
  #5  
Old July 19th, 2004, 02:35 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Actually, you don't wrap quotes around a NULL, right? So you'd actually need to do validation: If no value, set to NULL with no quotes; if there's a value, wrap quotes around it. In either case, use the string "SET phone = $phone " as you listed it above. I believe that if you insert the word NULL in quotes, it goes in as the word NULL and not as a NULL value. Give it a shot and see.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > How do I INSERT a NULL using PHP?


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway