On Wed, 2010-07-07 at 13:28 -0700, Don Wieland wrote: > Hello all, > > I am processing an array to build an INSERT string in PHP. The code > below I build an a separate array for the TARGET fields and the VALUES. > > I am trying to trap for a NULL ENTRY in a Date Input Field. Date > fields are identified with: $ffield['s']=='/' > > I tried to add the "&& !empty($fval)" to the test but it is giving my > an unexpected results. In my case, I have a Data of Birth field that > keeps populating in the future: So 1941-06-16 inserts in the DB as > 2041-06-16. > > foreach($form_fields as $ffield){ > $fval = is_array($ffield['f'])?joinFields($ffield['s'], > $ffield['f']):$_POST[$ffield['f']]; > $query_values[] = "'".mysql_real_escape_string($ffield['s']=='/' > && !empty($fval) ?date('y-m-d',strtotime($fval)):$fval)."'"; > } > > Will anyone point out the problem with this CODE? > > Don Wieland > I can't see anything immediately wrong, but the tertiary operators here mixed in with the mysql_ function and string concatenation don't make for easy reading! Maybe add some brackets to partition things off a bit to make the code easier on the eye. :p Have you tried echo'ing out the queries to see if they actually look well-formed? One place it could fall over is if the values you're using in it aren't well formed. Lastly, you're using a $_POST field directly in your query if the first tertiary if/else fails. You should at the very least validate it to make sure it's in the form you expect, which has to at least be something that can be parsed and processed by strtotime() which you're using in your example. Thanks, Ash http://www.ashleysheridan.co.uk