Shamrox Posted January 29, 2008 Share Posted January 29, 2008 I've got a simple text field that stores the order date. I'd like it to default to the current date, which is not a problem, but if I open a record that already has a date in the database, I need that to show. I tried to alter my code as seen below, but it's not working right. Can someone help? Order Date <input class="w8em format-m-d-y divider-slash highlight-days-12 range-low-today no-transparency" id="dp-normal-1" size="10" name="orderdate" type="text" value=" <?PHP if (@$orderdate == ""){ echo date('m/d/Y') ; }else{ echo @$orderdate; } } ?>"> Link to comment https://forums.phpfreaks.com/topic/88448-default-date-issue/ Share on other sites More sharing options...
Shamrox Posted January 29, 2008 Author Share Posted January 29, 2008 seems simple. anyone?? Link to comment https://forums.phpfreaks.com/topic/88448-default-date-issue/#findComment-452774 Share on other sites More sharing options...
akitchin Posted January 29, 2008 Share Posted January 29, 2008 first off, you have one too many closing braces in there as far as i can tell. second, why are you using error suppressants (@) before the variable name? third, are you sure $orderdate exists? fourth, how exactly is it "not working right?" if you want to see whether the variable is empty, i would suggest using empty($orderdate) instead of == "". Link to comment https://forums.phpfreaks.com/topic/88448-default-date-issue/#findComment-452901 Share on other sites More sharing options...
Shamrox Posted January 29, 2008 Author Share Posted January 29, 2008 I inherited the code from the last coder the client used. The code is full of those suppressants. Orderdate does exist as i checked via the database and also the current page that uses the old code. Not working, meaning, if i select a record that already has been saved with an orderdate, and i view it via the page that this code is in, that field doesn't get populated with the orderdate as it should. I will try your "empty" method and count my braces as well. Link to comment https://forums.phpfreaks.com/topic/88448-default-date-issue/#findComment-452903 Share on other sites More sharing options...
Shamrox Posted January 29, 2008 Author Share Posted January 29, 2008 Here is what I changed the code to and when the page loads the orderdate field is blank. So, it's not working for a new blank record and putting today's date, and it's not working when i load an old record that already has the orderdate field populated. Any ideas? <input class="w8em format-m-d-y divider-slash highlight-days-12 range-low-today no-transparency" id="dp-normal-1" size="10" name="orderdate" type="text" value=" <?PHP if (empty($orderdate)){ echo date('m/d/Y') ; }else{ echo $orderdate; } ?>"> Link to comment https://forums.phpfreaks.com/topic/88448-default-date-issue/#findComment-452917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.