Jump to content

Recommended Posts

I have a list of attendees for a selected event. At the end of each row are the radio buttons for (Present) and (Absent). It updates the first attendee in the list but not the rest. It seems that foreach ($Attendee as $checked){

should loop though the complete list of attendees. I`m doing something wrong, I need some help. Thank you.

 

<?php
// process the action inputs

$sAction = $_POST['Action'];
$EventID = $_POST['EID']; // from ListEvents button=Attendees
$per_ID = $_POST['PerID'];
$EvtName = $_POST['EName'];
$EvtDesc = $_POST['EDesc'];
$EvtDate = $_POST['EDate'];


// delete attendees from event

if ($sAction=='Drop'){
  $dpeEventID=$_POST['DelPerEventID'];
  $dpePerID=$_POST['DelPerID'];
  $dpeSQL = "DELETE FROM event_attend WHERE event_id=$dpeEventID AND person_id=$dpePerID LIMIT 1";
  RunQuery($dpeSQL);
  $ShowAttendees = 1;   
}
// count attendees for event

$checked = $_POST['Attendee'];
$Attendee = array('Present','Absent');
if (isset($_POST['Attendee'])){	
$attSQL = "UPDATE event_attend SET event_count='$checked'
		  WHERE event_id='$EventID' AND person_id='$per_ID'";
}		foreach ($Attendee as $checked){
	$rsAttend=mysql_query($attSQL);		
}
// Construct the form
?>  
<tr><td colspan="6" align="right"><input type="submit" align="right" style="font-size: 12px;" name="Attendee" value="Attendance"></td>

      <form method="POST" action="EditEventAttendees.php" name="DeletePersonFromEvent">
          <input type="hidden" name="DelPerID" value="<?php echo $per_ID; ?>">
          <input type="hidden" name="DelPerEventID" value="<?php echo $EventID; ?>">
          <input type="hidden" name="EID" value="<?php echo $EventID; ?>">
          <input type="hidden" name="EName" value="<?php echo $EvtName ?>">
          <input type="hidden" name="EDesc" value="<?php echo $EvtDesc ?>">
          <input type="hidden" name="EDate" value="<?php echo $EvtDate ?>">
	  <input type="hidden" name="PerID" value="<?php echo $per_ID; ?>">
          <input type="radio" name="Attendee" value="Present" checked="checked">Present
          <input type="radio" name="Attendee" value="Absent" >Absent&nbsp 
	  <input type="submit" style="font-size: 9px;" name="Action" value="<?php echo gettext("Drop"); ?>"class="icbutton" onClick="return confirm('Are you sure you want to DELETE <?php echo $per_FirstName." " .$per_LastName; ?> from <?php echo $EvtName; ?>&nbsp?')">
      </form>
     
/code]

Link to comment
https://forums.phpfreaks.com/topic/181923-attendance-form-with-radio-buttons/
Share on other sites

if you want the check boxes to be treated as an array, you need to signify to HTML that it is an array. so instead of the name attribute being name="Attendee" you need to set the name attribute to be name="Attendee[]".

 

you access it normally (IE $_POST['Attendee'];) but its an array now, instead of a single value

 

 

Ok I changed the code brackets, and moved the foreach function, and now I`m not getting the word Array in my table column. But it still only updates the first person in my attendee list. I`m still doing something wrong. Need help please. Thank you.

 

$checked = $_POST['Attendee'];

$Attendee = array('Present','Absent');

if (isset($_POST['Attendee'])){

} foreach ($Attendee as $checked){

$attSQL = "UPDATE event_attend SET event_count='$checked'

  WHERE event_id='$EventID' AND person_id='$per_ID'";

} $rsAttend=mysql_query($attSQL);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.