liamloveslearning Posted June 4, 2008 Share Posted June 4, 2008 hey everyone, im having trouble trying to delete a row from my table, ive never used delete functions before and im still learning or trying to learn php, ive a delete button on my page which posts to my delete.php which the link works only it doesnt remove the recod, can somebody have a look at my code and suggest why this could be happening, also how i can fix it? im not asking for the answer or an easy fix i justwant to know how to do it, thanks table with data page <div id="listmsg_inbox1"> <div> <form action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" method="post" id="form1"> <table cellpadding="2" cellspacing="0" width="100%"> <thead> <tr class="KT_row_order"> <th align="center" valign="top" class="message_header"> Check </th> <th align="left" valign="top" class="message_header" id="datetime">Date</th> <th align="left" valign="top" class="message_header" id="sender">From</th> <th align="left" valign="top" class="message_header" id="recieved">Status</th> <th align="left" valign="top" class="message_header" id="subject">Subject</th> </tr> </thead> <tbody> <?php if ($totalRows_msg_inbox == 0) { // Show if recordset empty ?> <tr> <td colspan="5">You have no messages</td> </tr> <?php } // Show if recordset empty ?> <?php if ($totalRows_msg_inbox > 0) { // Show if recordset not empty ?> <?php do { ?> <tr class="<?php echo @$cnt1++%2==0 ? "" : "KT_even"; ?>"> <td align="center" class="message_rows"><input type="checkbox" name="kt_pk_messages_test" class="id_checkbox" value="<?php echo $row_msg_inbox['id']; ?>" /> <input type="hidden" name="id" class="id_field" value="<?php echo $row_msg_inbox['id']; ?>" /></td> <td class="message_rows"><div><?php echo KT_formatDate($row_msg_inbox['datetime']); ?></div></td> <td class="message_rows"><div class="KT_col_sender"><?php echo KT_FormatForList($row_msg_inbox['sender'], 20); ?></div></td> <td class="message_rows"><div class="KT_col_recieved"><?php echo ($row_msg_inbox['recieved'] == 1)?"read":"unread"; ?></div></td> <td class="message_rows_subject"> <div class="KT_col_subject"> <a href="mail_viewmsg.php?msg_id=<?php echo $row_msg_inbox['id']; ?>" class="message_rows_subject"><?php echo $row_msg_inbox['subject']; ?></a></div></td> </tr> <?php } while ($row_msg_inbox = mysql_fetch_assoc($msg_inbox)); ?> <?php } // Show if recordset not empty ?> </tbody> </table> <div> <div> <div align="right"><br /> <?php $nav_listmsg_inbox1->Prepare(); require("includes/nav/NAV_Text_Navigation.inc.php"); ?> <br /> <br /> </div> </div></div> <div> <div> <div align="left" class="message_header"><a class="message_header_text" href="delete.php" onclick="nxt_list_delete_link_form(delete.php); return false;">Delete selected</a></div> </div> </div> </form> </div> <br class="clearfixplain" /> </div> delete page <?php require_once('Connections/db99.php'); ?> <?php session_start(); header("Location:mail_inbox.php"); $user = $_SESSION['kt_login_id']; //We need to get the total number of private messages the user has $sql = mysql_query ("SELECT pm_count FROM members WHERE member_id='$user'"); $row = mysql_fetch_array ($sql); $pm_count = $row['pm_count']; //A foreach loop for each pm in the array, get the values and set it as $pm_id because they were the ones selected for deletion foreach($_POST['pms'] as $num => $pm_id) { //Delete the PM mysql_query("DELETE FROM messages_test WHERE id='$pm_id'"); //Subtract a private message from the counter! YAY! $pm_count = $pm_count - '1'; //Update that users pm count. . . mysql_query("UPDATE members SET pm_count='$pm_count' WHERE member_id='$user'"); } ?> Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 i also noticed thie "foreach($_POST['pms']" on my delete page, does this function grab data from the url? if so i dont think im posting my row id through the url, nor is it named pms? ??? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 4, 2008 Share Posted June 4, 2008 im not asking for the answer or an easy fix i justwant to know how to do it, thanks lol, so you're not asking for the answer you just want to know how to do it? On this line: foreach($_POST['pms'] as $num => $pm_id) It appears that you wanted to cycle through something, perhaps some checkboxes. However, unless im being completely blind, there's no input with the name pms on your form. On a site note, there's really no point in storing the number of pm's a user has in the database. Just count the rows whenever you need the number. Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 haha yeah, well i wanted to know how id go about fixing it rather than someone just post me a correct version of the page, and yeah; my table has checkbox's where the user can selecte certain ones in which they can delete, so would my delete button be something similiar to deletephp?='pms' or the correct string (i know mine isnt correct) i apologize for sounding really amateur Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 so does anyone know what I'm missing? :-\ Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 I'm wondering how any of that runs with header("Location:mail_inbox.php"); before it. Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 well can i ask what that does? and why if not it shouldnt be there? ive still got an awful to learn :-\ Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 It loads the page mail_inbox.php and nothing after that line will run. Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 ahh brilliant thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 Now a question for you. If you don't know it's purpose, why are you using it? Quote Link to comment Share on other sites More sharing options...
runnerjp Posted June 4, 2008 Share Posted June 4, 2008 haha that is your problem... i think your using a program or some 1 elses code and editing it.. oh and dont forget TOPIC SOLVED mod Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 im using scripts trying to understand how it works, im just messing about with certain aspects of stuff; i learn better doing things rather than studying Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 That's fine, and I agree, poking at other's code will help you learn. But you also need to learn what each line does. When you don't understand a line of code, check the PHP manual and see what it does. That way you can actually use it for a reason and know what will happen when that line of code gets executed. Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted June 4, 2008 Author Share Posted June 4, 2008 yeah, ive taken some books from the local library but they seem to be written for those who have a basic knowledge already; thanks tho Quote Link to comment 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.