SkyRanger Posted April 25, 2007 Share Posted April 25, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/ Share on other sites More sharing options...
dsaba Posted April 25, 2007 Share Posted April 25, 2007 $del_id = $checkbox[$i]; is that an array? because if you're trying to pull that out of the form and you're posting data you should write $del_id = $_POST['nameofinput']; Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-238163 Share on other sites More sharing options...
SkyRanger Posted April 25, 2007 Author Share Posted April 25, 2007 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(); Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-238247 Share on other sites More sharing options...
kalivos Posted April 25, 2007 Share Posted April 25, 2007 you can always add print_r($checkbox); just to make sure that the keys are what you intended. Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-238249 Share on other sites More sharing options...
SkyRanger Posted April 25, 2007 Author Share Posted April 25, 2007 Yeah just checked so It must be something in the mysql, and the arrays are what they are suppose to be Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-238268 Share on other sites More sharing options...
SkyRanger Posted April 25, 2007 Author Share Posted April 25, 2007 ~bump~ Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-238417 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Still can't figure out why this isn't deleting, anybody have any ideas or is there a coding error I am missing? Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-239373 Share on other sites More sharing options...
sasa Posted April 26, 2007 Share Posted April 26, 2007 where you setup variable $count? Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-239382 Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 <?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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-239400 Share on other sites More sharing options...
SkyRanger Posted April 26, 2007 Author Share Posted April 26, 2007 Awsome, it sort of works...lol, it does do what I need it to do but need to fix a bit of my current code, which is causing my page not to reload properly. thanks boo_lolly Quote Link to comment https://forums.phpfreaks.com/topic/48638-solved-multi-delete-problem/#findComment-239430 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.