howdy all … my first post on here. Thanks in advance!
I am having trouble with processing multiple checkboxes that are created dynamically and processed dynamically.
The view and submit are in the same file as you will see.
Use the form for a little bit and see the issue. If you check multiple people and save, then go back and uncheck someone and save, go back and the other people are unchecked and the person who you just unchecked is checked … if that made any sense.
Take a look.
link is http://69.175.21.50/~stbriga1/app/attendance/
[php]
<?php $docroot = "../"; include($docroot.'inc/functions.inc.php'); $cmd = $_GET['cmd']; $id = $_GET['id']; if (isset($cmd)) {} else { $cmd = 'view'; } switch ($cmd) { case 'view': do_view(); break; case 'view_attendance': do_view_attendance($id); break; case 'submit': do_submit($id); break; } // ################################################################################################# function do_view() { $docroot = "../"; dbConnect(); // top navigation location, // Values: Home, Admin, Members, Attendance, Finance, Friends, Instruments, Equipment, Music Library, Products, Jobs $current_menunav = "Attendance"; // left nav bar location, //Values: Welcome, Support, Add, List, Attendance, Scriptures $current_leftnav = "Home"; site_header("Home", $docroot, $current_menunav); $sql = "SELECT * FROM `_events`"; $result = mysql_query($sql) or perish ("Unable to execute SQL query on database ::\r\n" . mysql_error()); ?>
<h3>Attendance to Events</h3><br/>
<div id="container">
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody>
<?php
$i=1;
while ($row = mysql_fetch_array($result)) {
if ($i % 2) { $css = "odd_gradeX";} else { $css = "even_gradeC";}
echo ' </tbody>
</table>
</div>
</div>
<?php
site_footer($docroot, $current_menunav, $current_leftnav);
}
// #################################################################################################
function do_view_attendance($id) {
$id = $_GET['id'];
$docroot = '../';
dbConnect(); // Connect to the DB
$sqlevents = "SELECT * FROM `_events` WHERE id = '".$id."'";
$resultevents = mysql_query($sqlevents) or perish ("Unable to execute SQL query on database :: \r\n" . mysql_error()); $sqlinstruments = "SELECT * FROM `instrument_names`"; $resultinstruments = mysql_query($sqlinstruments) or perish ("Unable to execute SQL query on database ::
\r\n" . mysql_error()); // change to handle more delicately... die for now if ($rowevents = mysql_fetch_array($resultevents)) { // top navigation location, // Values: Home, Admin, Members, Attendance, Finance, Friends, Instruments, Equipment, Music Library, Products, Jobs $current_menunav = "Attendance"; // left nav bar location, //Values: Welcome, Support, Add, List, Attendance, Scriptures $current_leftnav = "Home"; site_header("Home", $docroot, $current_menunav); } else { // bogus id sent? can't be editing... exit; } echo '
Event : '.$rowevents['name'].' at '.$rowevents['place_name'].'
'; ?>Here ? | ||
'.$rowinstruments['name'].' | ||
'.$rowmembers['fn'].' '.$rowmembers['ln'].' | <input type="checkbox" name="value[]" value="'.$rowmembers['id'].'"';
$sqlattendance = "SELECT * from `attendance` WHERE `member_id` = '".$rowmembers['id']."' AND `event_id` = '".$rowevents['id']."'";
$resultsattendance = mysql_query($sqlattendance) or perish ("Unable to execute SQL query on database :: \r\n" . mysql_error()); if ($result = mysql_fetch_array($resultsattendance)) { echo ' checked';} echo '> |
|
\r\n" . mysql_error()); if ($result = mysql_fetch_array($resultsattendance)) { $sqlcheck = "SELECT `id` FROM `attendance` WHERE event_id = '".$id."'"; $resultcheck = mysql_query($sqlcheck) or perish ("Unable to execute SQL query on database ::
\r\n" . mysql_error()); while ($rowcheck = mysql_fetch_array($resultcheck)) { if ( $result['id'] != $resultcheck['id'] ) { mysql_query($sql = "DELETE FROM `attendance` WHERE `id` = '".$result['id']."'") or perish(mysql_error()); } else { $sql = "INSERT INTO `attendance` ( `member_id`, `event_id`, `date_entered` ) VALUES ( '".$aValue[$i]."', '".$id."', '".$date."' )"; mysql_query($sql) or perish($sql."
\r\n" . mysql_error()); } } } else { $sql = "INSERT INTO `attendance` ( `member_id`, `event_id`, `date_entered` ) VALUES ( '".$aValue[$i]."', '".$id."', '".$date."' )"; mysql_query($sql) or perish($sql."
\r\n" . mysql_error()); } } } } redirect('index.php', 'Attendance Index', ''.$N.' attendance records entered. Returning to main menu.', $debug ? 600 : 2); exit(); } ?>
[/php]