This is a fairly easy question, but my mind is drawing a blank right now. I have a form with 5 input fields to update a Postgres DB. I want to have the query recognize if the the fields are empty or not, but I'm forgetting how to code it. Can someone help me with this? I'm thinking it's something like:
if ($field1 = "") { $query = "UPDATE....................
Is this right?
u can also use this
if(!isset($field1)) { //code
}
or u cud try
if($field1==NULL) { //code }
n e help?
} .....This one didn't work.
Does the second one recognize it as "If this is null, then do this"?
I'm trying to get it to do "If Field1 isn't null, then do this"....
Thanks!
the !isset isn't what you want.
you are looking for a varibable that IS SET, but the value is NULL.
if($blah == NULL) {
or
if(!$blah) { }
you probably want if(!$blah), because if($blah == NULL) will return false if blah is set to an empty string "" (i think)
No, I'm looking for a variable that is NOT NULL. In other words, if Field1 and Field4 of the form are updated, I want the query to only update field1 and field4.
... so
if($blah) { }
you are probably going to want something like
if($blah && ($blah != $oldblah)) { update database }
BeAuTiFul!!!
if($status && ($status !==NULL)) {
Worked great. Thanks!