dannyp100 Posted February 8, 2013 Share Posted February 8, 2013 I'm having trouble trying to create a delete function to delete inbox messages. This is my delete form <?php include 'gradnetconn.php'; require_once ('webpage.class.php'); include 'functions.php'; session_start(); $messageTo = $_SESSION['userID']; if (!(isset($_SESSION['userID']) && $_SESSION['userID'] != '')) { echo "Log in to send a message" ; header ("Location: login.php"); exit(); } else { echo "You aree logged in, please feel free to delete a message "; } $sql="SELECT * FROM gn_messages WHERE messageTo = $messageTo AND messageDeleted = '0' ORDER BY messageDate DESC"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action="deletemessagesprocess.php"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete A Message</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Message ID</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>From</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Subject</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Messge Contents</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['messageID']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['messageID']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageFrom']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageSubject']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['messageBody']; ?></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> </table> </form> </td> </tr> </table> This is my delete form process file: <?php include 'gradnetconn.php'; include 'functions.php'; session_start(); { for($i=0;$i<$count;$i++){ $del_id = $chk[$i]; $sql = "DELETE FROM gn_messages WHERE messageID='$del_id'"; $result = mysql_query($sql); } if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> I know this is completetly wrong, I need help on it, how to get the processing right in the second file so it actually deletes the messages that are checked. Any soolutions/ advice and talking my through code solutions would be so great! Quote Link to comment https://forums.phpfreaks.com/topic/274223-php-mysql-checkbox-delete-messages/ Share on other sites More sharing options...
tomtimms216 Posted February 8, 2013 Share Posted February 8, 2013 why aren't you just passing the checkbox array values to your delete form process file and just foreach through your array and delete where messageID = $id. Quote Link to comment https://forums.phpfreaks.com/topic/274223-php-mysql-checkbox-delete-messages/#findComment-1411095 Share on other sites More sharing options...
Barand Posted February 8, 2013 Share Posted February 8, 2013 (edited) Just use a single query $delList = join(',', array_map('intval', $_POST['checkbox'])); $sql = "DELETE FROM gn_messages WHERE messageID IN ($delList)"; Edited February 8, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/274223-php-mysql-checkbox-delete-messages/#findComment-1411117 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.