Hi. I'm no expert here, and I need some help.
This form does not update the database. I know it is accessing the database because the checkbox and radio buttons variables are good, but there is no result posted.
Can anyone tell me what is wrong here.

<?php
session_start(); 

// Place Session variable 'recid' into local variable
	$recid 		 = $_SESSION['recid'];
	$username    = $_SESSION['name'];
	$school    = $_SESSION['college'];
//Connect to the database
include_once "demo_conn.php";
// Query members data from the database and organise it for display
$sql = mysql_query("SELECT group1, group2, group3, group4, group5, group6 FROM members WHERE recid='$recid' LIMIT 1");
while($row = mysql_fetch_array($sql)){
$group1 = $row['group1'];
$group2 = $row['group2'];
$group3 = $row['group3'];
$group4 = $row['group4'];
$group5 = $row['group5'];
$group6 = $row['group6'];
}

// Process the form 
if ($_POST['group']) {
    $userGroup = $_POST['group'];
	
	foreach($_POST['snames'] as $x) {
		mysql_query("UPDATE users SET userGroup='$userGroup' WHERE recid='$recid' AND userId='$x'");
	}
    echo 'Selected students have been updated to new groups.<br /><br />
To return to your editing page, <a href="member_account.php">click here</a>';
exit();
} // close if posted

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Edit Your User Group Names</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
</head>
<body>
<table align="center" cellpadding="8" cellspacing="8">
  <tr>
    <td width="100"></td>
    <td width="160"><div align="left"> <font size="-1">Select <?php echo "$group1"; ?> students.</font></div></td>
    <td width="10"></td>
    <td width="150"><font size="-1">Send students to ....&nbsp;&nbsp;</font><font color="#CC0000">&nbsp;</font></td>
    <td width="30"></td>
    <td width="190"><div align="left"><font size="-1"></font></div></td>
  </tr>
<?php
// Query member data from the database
$query1 = mysql_query("SELECT userId FROM users WHERE managerId='".$recid."' AND userGroup='".$group1."' ORDER BY userId ASC");
while($row1 = mysql_fetch_array($query1))
{

$firstGroup .=$row1['userId']. ' <input type="checkbox" name="snames[]" value="'.$row1['userId'].'" /> ' . "&nbsp;&nbsp;&nbsp;&nbsp;<br /><br>";

}
?>
  <form method="post" enctype="multipart/form-data" action="send_stud_gp_test.php">
    <tr>
      <td>&nbsp;<br /></td>
    </tr>
    <tr>
      <td width="100"></td>
      <td width="160" style="text-align:right;"><?php echo $firstGroup;?></td>
      <td width="10"></td>
      <td width="150" style="text-align:left;">
          <input type="radio" name="group" value="<?php echo $group2; ?>" />
          &nbsp;&nbsp;&nbsp;<?php echo $group2; ?>
        <p>
          <input type="radio" name="group" value="<?php echo $group3; ?>" />
          &nbsp;&nbsp;&nbsp;<?php echo $group3; ?>
        <p>
          <input type="radio" name="group" value="<?php echo $group4; ?>" />
          &nbsp;&nbsp;&nbsp;<?php echo $group4; ?>
        <p>
          <input type="radio" name="group" value="<?php echo $group5; ?>" />
          &nbsp;&nbsp;&nbsp;<?php echo $group5; ?>
        <p>
          <input type="radio" name="group" value="<?php echo $group6; ?>" />
          &nbsp;&nbsp;&nbsp;<?php echo $group6; ?>
        <p>
          <input type="radio" name="group" value="noGroup" />
          &nbsp;&nbsp;&nbsp;Deactivate student.
        <p>
          <input type="submit" value="submit" name="Send Data">
  </form>
  	  </td>  
    </tr>  
</table>
</body>
</html>

if ($_POST) {
$userGroup = $_POST;
foreach($_POST as $x) {
mysql_query("UPDATE users SET userGroup='$userGroup' WHERE recid='$recid' AND userId='$x'");
}
echo 'Selected students have been updated to new groups.<br /><br />
To return to your editing page, <a href="member_account.php">click here</a>';
exit();
} // close if posted

shouldn't $userGroup=$_POST be array too? If so, i think you should specify what field to process in query:

"UPDATE users SET userGroup='$userGroup[]' WHERE recid='$recid' AND userId='$x'"

Thanks for your comment, but the page didn't like that at all. It just returned a white screen.

I suppose that $_POST has more than one value (array). If so, you should use some loop and save values in new array (or use the same $_POST), and in query get that values by $userGroup[0] or something like that.
I'm at the similar level of knowledge as you are, so don't take my notes as an expert solution.

EDIT: sorry, just saw that its radio button, no array than

'group' is a radio button, but 'snames' is an array of indeterminate length, because it lists all the students in a particular classroom, which of course, will change from time to time.
I think you might be a bit further along than me though.

I mean, I have an array of checkboxes, but a set list of radio buttons.

Further or not, we still know very little :D
Don't have any idea about your code anymore, sorry

Thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.