Reputation: 1045
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.
Upvotes: 0
Views: 1307
Reputation: 2825
No need to invent anything:
$post['Date'] == '0000-00-00'
Also, you should use NULL
instead of default in most cases.
Upvotes: 0
Reputation: 79031
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'];
}
Upvotes: 1
Reputation: 12806
You don't want to use var_dump()
. But it would help if you told us the structure of the value of $post['Date']
.
You want to use ==
, not =
for your first if
statement. You should be comparing, not assigning, (a) value(s).
The second if
statement can just be changed to an else
.
Just checking, but do you mean $_POST['Date']
rather than $post['Date']
?
Upvotes: 2