pikemsu28 Posted September 27, 2006 Share Posted September 27, 2006 I hope someone can help me with my code....Or atleast point me in the right direction. I've read numerous threads about using checkboxes to delete records from a database but cannot seem to get it to work.Basically, I want to view records that have been posted by users that will enable them to delete the record by selecting a checkbox and hitting submit. It should allow them to select multiple records to delete at once.here is ALL of my code:[code]<?php session_start();$_SESSION['MM_empid'] = '2';include ('library/error_handler.inc.php');virtual('/Connections/Nursing.php');$maxRows_report = 20;$pageNum_report = 0;if (isset($_GET['pageNum_report'])) { $pageNum_report = $_GET['pageNum_report'];}$startRow_report = $pageNum_report * $maxRows_report;mysql_select_db($database_Nursing, $Nursing);$query_report = "SELECT employee_info.first_name, employee_info.last_name, signups.signup_id, signups.account_id, signups.`date`, signups.shift, signups.team, signups.team_assign FROM employee_info, accounts, signups WHERE employee_info.info_id=accounts.info_id AND accounts.account_id=signups.account_id AND accounts.empid='".$_SESSION['MM_empid']."' ORDER BY employee_info.first_name, signups.team, signups.team_assign, signups.`date`, signups.shift";$query_limit_report = sprintf("%s LIMIT %d, %d", $query_report, $startRow_report, $maxRows_report);$report = mysql_query($query_limit_report, $Nursing) or die(mysql_error());$row_report = mysql_fetch_assoc($report);?><form id="form1" name="form1" method="post" action=""><table width="600" align="center" cellpadding="2" cellspacing="1" border="1" id="CBT Report"> <tr id="Labels"> <th width="30%" align="left" valign="bottom" class="style2">Team</th> <th width="20%" align="left" valign="bottom" class="style2">Team Assignment</th> <th width="25%" align="left" valign="bottom" class="style2">Date</th> <th width="15%" align="left" valign="bottom" class="style2">Shift</th> <th width="10%" align="center" valign="bottom" class="style2">Remove</th> </tr><?php$tmp_team='';$tmp_team_assign='';$tmp_date='';do { ?> <tr class="style2"> <?php $team = ucwords($row_report['team']); if($team != $tmp_team){ ?> <td valign="top" width="30%"><a href=TeamDescription.php><?php echo ucwords($row_report['team']); ?></a></td> <?php } else echo "<td width='30%'> </td>"; $tmp_team = $team; $team_assign = ucwords($row_report['team_assign']); if($team_assign != $tmp_team_assign){ ?> <td valign="top" width="20%"><?php echo ucwords($row_report['team_assign']); ?></td> <?php } else echo "<td width='20%'> </td>"; $tmp_team_assign = $team_assign; ?> <td valign="top" width="25%"><?php echo $row_report['date']; ?></td> <td valign="top" width="15%"><?php echo $row_report['shift']; ?></td> <td valign="top" width="10%" align="center"> <label> <input type="checkbox" name="id[]" value="<?php echo $row_report['signup_id']; ?>" /> </label> </td> <?php } while ($row_report = mysql_fetch_assoc($report)); ?> <tr align="center"> <td colspan="6"><input name="submit" type="submit" value="Delete" /></td> </tr></table></form><?phpmysql_free_result($report);?>[/code]I use dreamweaver so the connection to the database was thru dreamweaver.Every thread i've read says to use some varient of this code:[code]if(isset($_POST['delete'])){ foreach($_POST['delete'] as $i => $message_id){ mysql_query("DELETE * FROM message WHERE messageID='[b]$message_id[/b]'"); }}[/code]I've tried to modify it to support my code but always receive errors or the page just doesn't load.I dont know what to do. Any help would be greatly appreciated!!Jason Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/ Share on other sites More sharing options...
Barand Posted September 27, 2006 Share Posted September 27, 2006 Seehttp://www.phpfreaks.com/forums/index.php/topic,107464.msg431636.html#msg431636 Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-99827 Share on other sites More sharing options...
pikemsu28 Posted September 27, 2006 Author Share Posted September 27, 2006 Barand,I checked out the thread and tried inserting it into my code......the page would not even load.here is the updated code:[code]<?php session_start();$_SESSION['MM_empid'] = '2';include ('library/error_handler.inc.php');virtual('/Connections/Nursing.php');$maxRows_report = 20;$pageNum_report = 0;if (isset($_GET['pageNum_report'])) { $pageNum_report = $_GET['pageNum_report'];}$startRow_report = $pageNum_report * $maxRows_report;mysql_select_db($database_Nursing, $Nursing);$query_report = "SELECT employee_info.first_name, employee_info.last_name, signups.signup_id, signups.account_id, signups.`date`, signups.shift, signups.team, signups.team_assign FROM employee_info, accounts, signups WHERE employee_info.info_id=accounts.info_id AND accounts.account_id=signups.account_id AND accounts.empid='".$_SESSION['MM_empid']."' ORDER BY employee_info.first_name, signups.team, signups.team_assign, signups.`date`, signups.shift";$query_limit_report = sprintf("%s LIMIT %d, %d", $query_report, $startRow_report, $maxRows_report);$report = mysql_query($query_limit_report, $Nursing) or die(mysql_error());$row_report = mysql_fetch_assoc($report);?><form id="form1" name="form1" method="post" action=""><table width="600" align="center" cellpadding="2" cellspacing="1" border="1" id="CBT Report"> <tr id="Labels"> <th width="30%" align="left" valign="bottom" class="style2">Team</th> <th width="20%" align="left" valign="bottom" class="style2">Team Assignment</th> <th width="25%" align="left" valign="bottom" class="style2">Date</th> <th width="15%" align="left" valign="bottom" class="style2">Shift</th> <th width="10%" align="center" valign="bottom" class="style2">Remove</th> </tr><?php$tmp_team='';$tmp_team_assign='';$tmp_date='';do { ?> <tr class="style2"> <?php $team = ucwords($row_report['team']); if($team != $tmp_team){ ?> <td valign="top" width="30%"><a href=TeamDescription.php><?php echo ucwords($row_report['team']); ?></a></td> <?php } else echo "<td width='30%'> </td>"; $tmp_team = $team; $team_assign = ucwords($row_report['team_assign']); if($team_assign != $tmp_team_assign){ ?> <td valign="top" width="20%"><?php echo ucwords($row_report['team_assign']); ?></td> <?php } else echo "<td width='20%'> </td>"; $tmp_team_assign = $team_assign; ?> <td valign="top" width="25%"><?php echo $row_report['date']; ?></td> <td valign="top" width="15%"><?php echo $row_report['shift']; ?></td> <td valign="top" width="10%" align="center"> <?php echo "<input type='checkbox' name='delitem[]' value='".$row_report['signup_id']."'>"; ?> </td> <?php } while ($row_report = mysql_fetch_assoc($report)); ?> <tr align="center"> <td colspan="6"><input name="submit" type="submit" value="Delete" /></td> </tr></table></form><?php$items = join (',' , $_POST['delitem']);mysql_query ("DELETE FROM signups WHERE signup_id IN ($items)");echo "Selected items deleted";?><?phpmysql_free_result($report);?>[/code]did i place the code in the right spot? Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-99835 Share on other sites More sharing options...
Barand Posted September 27, 2006 Share Posted September 27, 2006 I usually place any update/delete code at the top of the script. That way, when the data is queried and listed, the changes can be seen. Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-99847 Share on other sites More sharing options...
pikemsu28 Posted September 28, 2006 Author Share Posted September 28, 2006 It's not working at all. No matter where i place the code, the page doesn't load. If i take the code out, the page loads just fine i just can't delete anything.[code]<?php$items = join (',' , $_POST['delitem']);mysql_query ("DELETE FROM signups WHERE signup_id IN ($items)");echo "Selected items deleted";?>[/code]no matter where i put this in my code the page doesn't load at all. I get the Apache Server has encountered a problem error requesting me to send the error report to microsoft then the "page cannot be displayed" shows. Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-100217 Share on other sites More sharing options...
pikemsu28 Posted September 28, 2006 Author Share Posted September 28, 2006 i've been playing around and i've finally got the page to load. But when i submit the form, i get the same errors as before and the page doesnt load. if i echo the query it displays properly but the records are not deleted.[code]]<?phpif (!isset($_POST['submit'])) {?>Form........<?php} else { $del = $_POST['del']; $num = count($del); for($i = 0; $i < $num; $i++){ $ID = $del[$i]; $sql = "DELETE FROM signups WHERE signup_id = '$ID'"; echo $sql."<BR><BR>";// echos the query which is right. mysql_query($sql); }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-100254 Share on other sites More sharing options...
pikemsu28 Posted September 28, 2006 Author Share Posted September 28, 2006 Thanks Barand!!I feel like a moron!!!! the user i was using to update the database didn't have DELETE privileges for the table.it works now!!thanks so much! Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-100275 Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 Good. I couldn't test it as I don't have your data. But I guess I'd have missed that condition though. Link to comment https://forums.phpfreaks.com/topic/22289-deleting-a-record-using-checkboxesresolved/#findComment-100279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.