Sending 0 instead "" when radio button unchecked

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Sending 0 instead "" when radio button unchecked

Post by Perfidus »

I have a collection of radio buttons that have to send several values via post to database. When they are checked, they send the value but when they are unchecked, they send "" (nothing) and it is stored in table (In which default content was 0) this cause me troubles.
How can I send alternative value 0 when unchecked or how can I prevent this <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>?
:(
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

Mybe there's a way that detect and converts all "" empty values send by post in 0, so no empty values are stored in database! Any hints?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

You could go:

if (!isset($_POST["myRadio"] || $_POST["myRadio"] == "") {
$myRadio = "0";
} else {
$myRadio = $_POST["myRadio"];
}
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post by Perfidus »

Thanks, it works!!
:lol:
Post Reply