i am making a php script where i use the IF/ELSEIF/ELSE statement. I have a table column with a NULL(empty) field and i am trying to store to that column something when the user decides to not click the submit button and i also clear the column field when the user submits. $field is storing that specific column.
if($field == NULL) {
$sql = mysqli_query("UPDATE table SET this = 'something' WHERE id='1'");
if(isset($_POST["x"])) {
$sql = mysqli_query("UPDATE table SET this = NULL WHERE id='1'");
} else {
echo "null1 error";
}
} elseif (!empty($field)) {
if(isset($_POST["x"])) {
$sql = mysqli_query($db_conx, "UPDATE table SET this = NULL WHERE id='1'");
} else {
echo "null2 error";
}
} else {
echo 'error';
}
The problem is that while i get what i want at the end the $_POST happens always from the ELSEIF statement and if i don't refresh the page(to test) and hit the submit button then the $_POST comes from the IF statement. What i am doing wrong here? PS: To be more specific on what i am doing is that a user gets some form/details that he needs to submit. I don't want him to bypass it without submission so i am storing it to the database until he submits the info. So even if he refresh the page or visit the page after a month he will get the same form until he submit the info.