PHP Array Null Values

Posted on 2011-10-01
Last Modified: 2012-05-12
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) {
          if (!empty($dtAssigned)){$update="UPDATE audit SET dateAssigned='$da' WHERE auditID=$editID";

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

Open in new window

Question by:rcowen00
    LVL 13

    Accepted Solution

    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

    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.

    Author Comment

    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.
    LVL 13

    Expert Comment

    by:Hugh McCurdy
    Data in the field would do it.  Thus the value of var_dump().  Glad you got it solved and thanks for the points.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now