User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Unread 7 Oct 2004, 01:18   #1
Mong
Forever Delayed
 
Join Date: Sep 2000
Location: www.netgamers.org
Posts: 1,475
Mong is on a distinguished road
Forms, null values, and PHP/MySQL

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.
__________________
Firefly Oper and General l4m3r - "I Do Stuff"

O2 Rip-off campaign

<vampy> plus i hate people ... i despise humanity as a whole

pablissimo "I'm still geting over the fact you just posted a pic of your own vomit"

Last edited by Mong; 7 Oct 2004 at 01:40.
Mong is offline   Reply With Quote
 



Forum Jump


All times are GMT +1. The time now is 03:47.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018