|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all
I'm using PHP to insert data into MySQL. I need to find a way of changing the SQL query depending on whether information has been entered by the user. If there is information, the SQL query would include '$longform', if there wasn't, it would be $longform (ie, without the single quotes). The reason I need this is that I need enter NULL if there isn't data. Quoting '$longform' enters the string "NULL" rather than the value NULL. Any help gratefully received. |
|
#2
|
|||
|
|||
|
Well, it all depends on how you are getting your variables. For example, you could do it this way:
PHP Code:
Good luck! Joe
__________________
Check out 4Life today! |
|
#3
|
|||
|
|||
|
Hi
Thanks I'm getting them via a $_POST, but there's 4 or 5 different fields that are potentially able to be NULL. I am trying to find a way of not doing a whole load of if() statements with SQL queries in. Regards F |
|
#4
|
|||
|
|||
|
You can use my above code to achieve that effect; you just have to test each variable by using "elseif(){}" statements.
PHP Code:
|
|
#5
|
|||
|
|||
|
Thanks
I suppose, thinking about it (this always helps!) I could build up my SQL query using your example, instead of writing error messages. Regards F |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > change sql query if null |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|