moogle1979 Posted January 3, 2009 Share Posted January 3, 2009 I am trying to set it up where records are deleted from a log file in mysql by coding checkboxes next to the table however it is not deleting them, I am thinking it is because the id's are not 1,2,3,4,5,6,etc. but more like 12,34,56,67,etc. here is the code and any help would be appreciated <?php session_start(); $SITE_ROOT = "http://www.rigganmore.com/"; include('../includes/connect.php'); if($_SESSION['login'] != "yessir") { header("Location: ".$SITE_ROOT."signin.php"); exit(); } if($_SESSION['access'] < "70") { header("Location: ".$SITE_ROOT."includes/msg.php?code=9"); exit(); } //query log files $query = mysql_query("SELECT * FROM log ORDER BY id ASC") or die(mysql_error()); $count=mysql_num_rows($query); ?> <!-- Starts the log files in html --> <h2 align="center">Administration Logs</h2> <h3 align="center">(From Admins / Mods / Volunteer Mods)</h3> <h4 align="center">Please Note: If the value in the "New" section is not changed, this indicates the user did not update that field</h4> <form name="form1" method="post" action=""> <table width="90%" border="1" align="center" cellpadding="2" cellspacing="2"> <tr style="font-weight:bold;font-size:12px;"> <td style="text-align:center">#</td> <td>Log ID:</td> <td>Username:</td> <td>Status:</td> <td>Date:</td> <td>Time:</td> <td>Updated User:</td> <td>New Username:</td> <td>New E-Mail:</td> <td>New Status:</td> <td>New Money:</td> <td>New Bank:</td> <td>New EXP:</td> <td>New LVL:</td> <td>New HP:</td> <td>New HP Max:</td> <td>Reason:</td> </tr> <?php // create the table with php and information, if a file is unchanged it will be noted while ($info = mysql_fetch_array($query)) { ?> <tr> <!-- check boxes being created --> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $info['id']; ?>"></td> <td><?php echo $info['id']; ?></td> <td><?php echo $info['username']; ?></td> <td><?php echo $info['status']; ?></td> <td><?php echo $info['date']; ?></td> <td><?php echo $info['time']; ?></td> <td><?php echo $info['updated_user']; ?></td> <td> <?php echo $info['new_username']; if ($info['new_username'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_email']; if ($info['new_email'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_status']; if ($info['new_status'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_money']; if ($info['new_money'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_bank']; if ($info['new_bank'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_exp']; if ($info['new_exp'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_lvl']; if ($info['new_lvl'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_hp']; if ($info['new_hp'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['new_hpmax']; if ($info['new_hpmax'] == "") echo "Unchanged"; ?> </td> <td> <?php echo $info['reason']; if ($info['reason'] == "") echo "Unchanged"; ?> </td> </tr> <?php } ?> <tr> <!-- delete button being created --> <td colspan="17" align="center" bgcolor="#FFFFFF"> <input name="delete" type="submit" id="delete" value="Delete"> <a href="../admin.php">Back</a> </td> </tr> <?php // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM log WHERE id='" . $info'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=log.php\">"; } } // End ?> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/139358-solved-delete-records/ Share on other sites More sharing options...
bubbasheeko Posted January 3, 2009 Share Posted January 3, 2009 Hey moogle, First, make your checkbox ID's unique. ie. id=<? echo $info['id']; ?> Second, the code to remove the checked items. $checkboxes = implode(', ', $_POST['checkbox']); // TO ALLOW US TO USE ONLY ONE MYSQL STATEMENT $delete_query = "DELETE FROM log WHERE id IN ($checkboxes)"; $mysql_query($delete_query) or die(mysql_error()); Give that a shot (make a backup first ) Quote Link to comment https://forums.phpfreaks.com/topic/139358-solved-delete-records/#findComment-728928 Share on other sites More sharing options...
moogle1979 Posted January 4, 2009 Author Share Posted January 4, 2009 Thanks, I took and reapplied the information at the top with the code you had under an if statement checking to see if the post was set and then performing the delete. However I took your mysql_query variable and just made it a mysql_query and it worked perfectly after making the changes. Quote Link to comment https://forums.phpfreaks.com/topic/139358-solved-delete-records/#findComment-729005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.