Hello.
[edit: much code here written as an example, so not tested, but you get the idea!]
I have a (large) table which (amongst other things) stores Yes/No/Maybe from a web form. The form goes a little like this:
Code:
Yes <input type="radio" name="foo" value="1">
No <input type="radio" name="foo" value="0">
Maybe <input type="radio" name="foo" value="2">
Yes <input type="radio" name="foo2" value="1">
No <input type="radio" name="foo2" value="0">
Maybe <input type="radio" name="foo2" value="2">
Now, in the DB the field default is set to NULL. So how come if the user submits the form without selecting anything (perfectly okay), it still records 0 in the DB? I would have thought it would remain as NULL. Also I tried setting the default to 9 (so Not NULL) as a test, 0 still gets inserted. I'm assuming it's a prob with the query I build in PHP, thus...
Code:
$foo = $_POST['foo'];
$foo2 = $_POST['foo2'];
$query = "INSERT INTO `footable` (`foo`, `foo2`) VALUES ('$foo', '$foo2');";
If I tick yes/no for the input
foo but not
foo2 then do
print_r($_POST), it only tells me that
foo exists. Because of course,
foo2 was never set, so it doesn't exist in the $_POST array. So the annoying thing is that if I do
echo $query, I get the following:
Code:
INSERT INTO footable (foo, foo2) VALUES ('1', '');
So I'd assume that literally nothing would be inserted into the DB field called
foo2?
Can anybody shed some light on this? It's REALLY pissing me off
If you can think of a solution or easy hack, then let me know please! It's taken months to develop this set of forms, but the "bug" only just became an issue, and I have to deliver on Friday! :
Ta muchly,
M.