• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

PHP Array Null Values

The attached code does not work.  What I am attempting to do is to only update records that do not have a null value but the code is updating the field to "0000-00-00" vs leaving it null.   Any suggestions?  Thank you.
$i = 0;
        foreach ( $dateAssignedArray as $editID => $da) {
          $dtAssigned=rtrim($da);
          if (!empty($dtAssigned)){$update="UPDATE audit SET dateAssigned='$da' WHERE auditID=$editID";

        $updateRow=mysql_query($update)or die(mysql_error());
        $i++;}
          ELSE {
        }
       }

Open in new window

0
rcowen00
Asked:
rcowen00
  • 2
1 Solution
 
Hugh McCurdyCommented:
I'm not sure but I'll guess.  I suggest some var_dump() calls on $da and $dtAssigned.  I wonder if rtrim() is somehow having trouble with a null string.  I don't see a definition for that case at http://php.net/manual/en/function.empty.php

Perhaps you should require that both $dtAssigned and $da not be empty.

if ( ( !empty ( $dtAssigned )) && ( !empty ( $da )))  

Open in new window


If that doesn't fix it, please try the var_dump() so we can see what's going on.
0
 
rcowen00Author Commented:
After running your suggestion, it didn't work but I realized because the field already had "0000-00-00" and I was deleting it, but that wasn't being looked at because it was null.  I realized that in most cases that will work when the current value is null but what if the user has a value in the field but wants to remove it, this will never work.  I believe then I want to check for isset.
0
 
Hugh McCurdyCommented:
Data in the field would do it.  Thus the value of var_dump().  Glad you got it solved and thanks for the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now