Jump to content

Recommended Posts

I am trying to get a multi update to work, but not sure why it won't work

 

<form method="posts" action="privatemessages.php" name="pmform">
<table .....
Form data here

This is in a cell by <td>
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rowpm['pmid']; ?>">
</td>
<td><input name="delete" type="submit" id="delete" value="Archive"></td>
</tr>
<?
if(isset($_POST["delete_x"])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "UPDATE pms SET opened='a' WHERE pmid='$del_id'";
$result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error());
}

// if successful redirect to back to page
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=privatemessages.php\">";
}
}
mysql_close();
?>
</table>
</form>

Link to comment
https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/
Share on other sites

I tried changing that.. It never worked.

 

Here is the original code that I am working with:

 

...........sql connect and pull info here...........


<form name="form1" method="post" action="privatemessages.php">
<table width="700" border="0" cellspacing="0" cellpadding="0" class="forumtext">
  <tr>
    <td width="36"><div align="center"></div></td>
    <td width="200"><u><strong>Subject</strong></u></td>
    <td width="150"><u><strong>To</strong></u></td>
    <td width="150"><u><strong>From</strong></u></td>
    <td width="139"><u><strong>Received</strong></u></td>
    <td width="25"><u><strong>Delete</strong></u></td>
  </tr>
  <tr>
    <td colspan="6"> </td>
    </tr>
  <?
  while( $rowpm = mysql_fetch_array( $resultpm ) )
{

?>
  <tr>
    <td width="36"><div align="center">
<?
$pmstatus = $rowpm['opened'];


if($pmstatus == 'n'){
$pmnote = "<img src=\"images/pm/newmail.png\" />";
}elseif($pmstatus == 'y'){
$pmnote = "<img src=\"images/pm/read.png\" />";
}elseif($pmstatus == 'r'){
$pmnote = "<img src=\"images/pm/replied.png\" />";
}
echo $pmnote;
?>	
</div></td>
    <td><? echo "<a href=\"readpm.php?pmid=".$rowpm['pmid']."\">".$rowpm['subject']."</a></td>"; ?>
    <td><? echo $rowpm['to_name']; ?></td>
    <td><? echo $rowpm['from_name']; ?></td>
    <td><? echo $rowpm['time_sent']; ?></td>

    <td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rowpm['pmid']; ?>"></div></td>
  </tr>
  <? } ?>
  <tr>
    <td colspan="6"><div align="right">
      <input name="delete" type="submit" id="delete" value="Delete">
    </div></td>
    </tr>
</table>
</form>
<?
  include "inc/dbinfo.inc.php";

$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db ("$dbname");

if(isset($_POST["delete_x"])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "UPDATE pms SET opened='a' WHERE pmid='$del_id'";
$result = mysql_query($sql) or die ('I could not add information to the database because ' . mysql_error());
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=privatemessages.php\">";
}
}
mysql_close();

<?php
        foreach($_POST['checkbox'] as $key => $val){
                $sql = "
                        UPDATE
                                pms
                        SET
                                opened = 'a'
                        WHERE
                                pmid = '{$val}'
                ";
                mysql_query($sql) OR die(mysql_error());
        }
?>

 

that should work.

 

it can also be done like this:

<?php
        foreach($_POST['checkbox'] as $key => $val){
                $_POST['checkbox'][$key] = "'". $val ."'";
        }

        $pmidstring = implode(', ', $_POST['checkbox']);

        $sql = "
                UPDATE
                        pms
                SET
                        opened = 'a'
                WHERE
                        pmid
                IN
                        ({$pmidstring})
        ";
        mysql_query($sql) OR die(mysql_error());
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.