I have this PHP IF statement that is working 'fine':
if(EMPTY($_POST['review_date'])){
$review_date = NULL;
}
else {
$review_date = $_POST['review_date'];
}
The problem starts when I pass on the variable to the sqlsrv_query:
sqlsrv_query($connect,"UPDATE goals SET review_date='$review_date' WHERE id='$department'") or die(sqlsrv_errors());
In the case where IF statement is TRUE, the value in the review_date cell shows up as 1900-01-01, instead of NULL.
If I try to put quotes around the NULL value in the IF statement, I get the following error:
Notice: Array to string conversion in C:\xampp\htdocs\project\edit.php on line 30
If NULL is inserted into query directly, it executes as it should.
The Column Properties in the goals Table have Allow Nulls enabled and Default Value is set to (NULL).
Swifted through other questions but didn't really get anywhere.
What am I doing wrong here?
UPDATE 1:
As requested, here is the HTML code:
<form method="POST" action="edit.php">
Review date <i>(optional)</i>: <input type="date" name="review_date" value="" placeholder="dd/mm/yyyy" >
<p><button type="submit">Save</button></p>
</form>
With regards to var_dumps:
var_dump($review_date);
Returned: NULL
var_dump($department);
Returned: string(2) "36"
var_dump(sqlsrv_query($connect,"UPDATE goals SET review_date='$review_date' WHERE id='$department'"));
Returned: resource(7) of type (SQL Server Statement)