|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
no... you woukd need to write
>>phone = '$phone' where id<< - Pheifel |
|
#5
|
||||
|
||||
|
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.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > How do I INSERT a NULL using PHP? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|