I got great help here in a recent/prior thread showing me how to insert real NULLs into an int column of a MySQL database when a form with an empty input box is submitted.
But now I am having problems with an update form/update query.
The user can view their data as submitted so far and there an "Edit" button at each row that will give them a form allowing them to edit that record/row.
(VASTLY simplified Form)
print ("<form method=\"POST\" action=\"WRITscript.php\"><tr><td><input type=\"hidden\" name=\"DATAPOINTID\" value=\"$DATAPOINTID\"></td><td><input type=\"text\" name=WRIT1 size=\"3\" value=$Row[WRIT1]><input type=\"hidden\" name=\"ACTION\" value=\"UPDATE\"><input type=\"submit\" value=\"SUBMIT AND SAVE my changes.\" name=\"B1\"></form></td></tr>\n");
The values seem to pass just fine to the script and are recieved at WRITscript.php:
$DATAPOINTID = $_POST[DATAPOINTID]))
//convert empty boxes submitted to NULL
// I THINK THE PROBLEM IS HERE BECAUSE BOTH '0' AND EMPTY STRINGS EVAL AS "TRUE" USING THE "empty" function
If (empty($_POST[WRIT1])) {
$WRIT1 = 'null';
} else {
$WRIT1 = $_POST[WRIT1];
}
and the (simplified) update query is like so:
$sql = "UPDATE DATAWRIT SET
WRIT1 = '$WRIT1',
WHERE DATAPOINTID = '$DATAPOINTID' LIMIT 1";
The problem is, if the user enters an actual '0', it gets stored as a NULL, just as if the box was left empty. I want the '0' to be stored as such, if that is what is entered.
Is there a method to accomplish this?
Thanks yet again!