View Full Version : radio checked

06-15-2010, 05:15 PM
Hey everybody! My current code works, but it is messy and seems too long. I am just asking for help to abridge and make it a little more concise. I am checking the status of a radio button preset against a mySQL table. For about ten fields their status can be (none, display, require)

function checkFields($field_num, $ch1, $ch2, $ch3)
if($field_num == "none")
$ch1 = 'checked'
else if($field_num == "display")
$ch2 = 'checked'
else if($field_num == "require")
$ch3 = 'checked'
$ch1 = 'checked'
//Ten of these:
function($fieldsArray[1], $fname1, $fname2, $fname3);

Then on the radio buttons this requires me to have 3 php variables for each each set to ' '. This was the best I could come up with. Possibly if there was a way to select radio->specific name->specific value = 'checked' ... Any ideas?

06-16-2010, 07:30 PM
Grouping check box as per below mentioned html and saving $status as shown may help on what is needed.

if(isset($_POST['save']) && $_POST['save'] != ''){
$status = $_POST['chkname'];
// then update mysql database tables with this status
<form action="page5.php" method="post">
<input type="checkbox" name="chkname" value="none">
<input type="checkbox" name="chkname" value="display">
<input type="checkbox" name="chkname" value="require">
<input type="submit" name="save" value="save">