0

Hi I'm trying use a datepicker on a field I have. I'm trying to set the date field up so the user can only edit this field if the date value in the database is set to deafault (0000-00-00). If there is a value that's not equal to default I want to show the date created.

Here's the code I have attempted:

          if( $post['Date'] = var_dump(checkdate(00, 00, 0000))){ 
          echo "<input type=\"text\" class=\"datepicker\" name=\"pDate\" style=\"border:#000099; margin:10px;\" value=\"";
          echo $post['Date'];
          echo "\"> <input id=\"start_dt\" class=\"datepicker\">";
          }
          if( $post['Date'] != var_dump(checkdate(00, 00, 0000))){ 
          echo "<span>date created: </span>";
          echo $post['Date'];

          }

It's not working atm so any help or a point in the right direction would be great. Please also take into account I haven't added any proper styling so I'm only after help with the functionality.

Many thanks.

4
  • 1
    The var_dump() does not do what you think it does. Commented Apr 1, 2012 at 9:30
  • Don't use var_dump() in this way... var_dump() is a developers' debugging statement, not a method of displaying data to end users, nor of parsing values for if tests Commented Apr 1, 2012 at 9:30
  • var_dump is for debug-outputting variables and does not return anything. So with $post['Date'] = var_dump(...) you are assigning null to $post['Date'] and null evaluates to false, so your condition is never met. Commented Apr 1, 2012 at 9:31
  • Are you referring to post variables by $post Commented Apr 1, 2012 at 9:39

3 Answers 3

2
  1. You don't want to use var_dump(). But it would help if you told us the structure of the value of $post['Date'].

  2. You want to use ==, not = for your first if statement. You should be comparing, not assigning, (a) value(s).

  3. The second if statement can just be changed to an else.

  4. Just checking, but do you mean $_POST['Date'] rather than $post['Date']?

Sign up to request clarification or add additional context in comments.

1 Comment

I am running a query to get the date from the database, basically what I'm wanting to do is if ((My database date) equals (the default date)){ Do something...
1

var_dump() is used for debugging purpose rather than inside conditional expression. Next, using = assigns the values not checks for them. You are assigning the values of var_dump() results to $post['Date'] So change them to ==

You should be trying to to something like this

  if( $post['Date'] == checkdate(00, 00, 0000)){ 
      echo "<input type=\"text\" class=\"datepicker\" name=\"pDate\" style=\"border:#000099; margin:10px;\" value=\"".$post['Date']"\">";
      echo "<input id=\"start_dt\" class=\"datepicker\">";
  } else {
      echo "<span>date created: </span>";
      echo $post['Date'];
  }

Comments

0

No need to invent anything: $post['Date'] == '0000-00-00'

Also, you should use NULL instead of default in most cases.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.