Jump to content

Default date issue


Shamrox

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.