Jump to content

[SOLVED] wont delete record


Recommended Posts

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'");
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/108706-solved-wont-delete-record/
Share on other sites

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? :P

 

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.

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  :D

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.