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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.