Jessica Posted September 10, 2012 Share Posted September 10, 2012 Okay, so? Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1376870 Share on other sites More sharing options...
jcbones Posted September 11, 2012 Share Posted September 11, 2012 You don't need a index in your form. while ($rows = mysql_fetch_array($SqlResult)); ?> <td align="center" bgcolor="#FFFFFF"><input name="need_delete[]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td> <?php Should be fine. Remove_Message() is returing a string of "False". It also has no database interaction, just sets a string in the form of a query. Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1376903 Share on other sites More sharing options...
the-botman Posted September 11, 2012 Author Share Posted September 11, 2012 can you please tell me where i am going wrong on the table? see it does not display corrctly it shows the first message 100% and allows me to tick and delete but the second message is not in the table and even if i tick it and click delete it does not do anything, i think thats part of my problem, how do i make them all show in the table with just one delete button at the bottom, right now there is one delete button next to each message. Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1376947 Share on other sites More sharing options...
the-botman Posted September 11, 2012 Author Share Posted September 11, 2012 can you please tell me where i am going wrong on the table? see it does not display corrctly it shows the first message 100% and allows me to tick and delete but the second message is not in the table and even if i tick it and click delete it does not do anything, i think thats part of my problem, how do i make them all show in the table with just one delete button at the bottom, right now there is one delete button next to each message. sorry this is my form $Spacing = " "; echo $Spacing.'<center>'."\n"; echo $Spacing.'<br>'."\n"; echo $Spacing.'<table border="0" cellpadding="0" cellspacing="0" style="color: #666;font-size:11px;width:550px;">'."\n"; echo $Spacing.' <tr height="15" align="left"><td><span class="Form_Title">Guestbook Messages</span><HR width="100%" SIZE="1"></td></tr>'."\n"; echo $Spacing.'</table>'."\n"; echo $Spacing.'<br>'."\n"; echo $Spacing.'<form name="form1" method="post" action="">'."\n"; echo $Spacing.'<table border="0" cellpadding="0" cellspacing="1" style="font-size:9pt;width:450px;">'."\n"; echo $Spacing.'<tr>'."\n"; echo $Spacing.'<td>'."\n"; echo $Spacing.'<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td>'."\n"; echo '<td><b>Delete</b></td>'."\n"; echo '<td><b> Date</b></td>'."\n"; echo '<td><b> Time</b></td>'."\n"; echo '<td align="center"><b>Message</b></td>'."\n"; echo '</tr>'."\n"; if ($RowCnt > 0) { $i = 0; while ($i < $RowCnt) { $Gbk_Id = mysql_result($SqlResult,$i,"Gbk_Id"); $Gbk_Date = mysql_result($SqlResult,$i,"Gbk_Date"); $Gbk_Time = mysql_result($SqlResult,$i,"Gbk_Time"); $Gbk_Name = mysql_result($SqlResult,$i,"Gbk_Name"); $Gbk_Message = mysql_result($SqlResult,$i,"Gbk_Message"); $Spacing = " "; echo $Spacing.'<tr style="background-color:#F5F5F5;color:#666;">'; echo '<td></td>'; echo '<td><input name="need_delete[]" type="checkbox" id="checkbox'.$Gbk_Id.'" value="'.$Gbk_Id.'"></td>'."\n"; echo '<td style="width:80px;"> '.$Gbk_Date.'</td>'; echo '<td style="width:60px;"> '.$Gbk_Time.'</td>'; echo '<td> <b>'.$Gbk_Name.'</b><br> '.$Gbk_Message.'</td>'; echo '<br></table>'."\n"; echo '<td><input name="delete" type="submit" id="delete" value="" class="Form_Btn_delete"></td>'."\n"; echo '</form>'."\n"; echo '</td>'."\n"; echo '</tr>'."\n"; $i++; Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1376961 Share on other sites More sharing options...
the-botman Posted September 11, 2012 Author Share Posted September 11, 2012 ok after trying every different way i got this working i am posting it for two reasons, 1. so others can learn from it and 2. for you guys to tell me if there is any bugs i should fix <?php include 'GbManager_Header.php'; $db_name="a4228367_bhawap"; // Database name $tbl_name="page_guestbook"; // Table name mysql_connect($GLOBALS["DbIP"].':'.$GLOBALS["DbPort"],$GLOBALS["DbUser"],$GLOBALS["DbPword"]); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); $Id = "page_guestbook"; include 'GbManager_Footer.php'; if ($count > 0) { $Spacing = " "; echo $Spacing.'<center>'."\n"; echo $Spacing.'<br>'."\n"; echo $Spacing.'<table border="0" cellpadding="0" cellspacing="0" style="color: #666;font-size:11px;width:550px;">'."\n"; echo $Spacing.' <tr height="15" align="left"><td><span class="Form_Title">Guestbook Messages</span><HR width="100%" SIZE="1"></td></tr>'."\n"; echo $Spacing.'</table>'."\n"; echo '<form name="form1" method="post" action="Guestbook.php?Cmd=Sign&Post=True">'; echo '<br>'; echo '<table border="0" cellpadding="0" cellspacing="1" style="font-size:9pt;width:550px;">'; echo '<tr style="background-color:#666;color:#FFF;"><td style="background-color:#FFF;color:#FFF;"></td><td><b> Delete</b></td><td><b> Name</b></td><td><b> Time</b></td><td><b> Date</b></td><td align="center"><b>Messages</b></td></tr>'; while ($rows = mysql_fetch_array($result)): echo '<tr style="background-color:#F5F5F5;color:#666;">'; echo '<td style="background-color:#FFF;"></td>'; ?> <td style="width:10px;"><input name="need_delete[<? echo $rows['Gbk_Id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['Gbk_Id']; ?>]" value="<? echo $rows['Gbk_Id']; ?>"></td> <td style="width:80px;"><? echo $rows['Gbk_Name']; ?></td> <td style="width:60px;"><? echo htmlspecialchars($rows['Gbk_Time']); ?></td> <td><? echo htmlspecialchars($rows['Gbk_Date']); ?></td> <td><? echo htmlspecialchars($rows['Gbk_Message']); ?></td> <?php echo '</tr>'; endwhile; echo '<tr>'; echo '<td align="center" style="width:50px;">'; echo '<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" color="#666666" type="submit" id="delete" value="" class="Form_Btn_delete" /></td></td>'; echo '</tr>'; echo '</form>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '<br>'; echo '<br>'; echo '</center>'; } else { $Spacing = " "; echo '<tr><td></td><td><font face="Verdana" size="2"><b>No Entries Found.</b></font><br></td></tr>'."\n"; } if(isset($_POST['need_delete'])) { $i = 0; while(list($key, $val) = each($_POST['need_delete'])) { $sql = "DELETE FROM $tbl_name WHERE Gbk_Id='$val'"; mysql_query($sql); } if($i > 0){ echo '<meta http-equiv="refresh" content="0;URL=Guestbook.php?Cmd=Sign&Post=True">'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1376991 Share on other sites More sharing options...
Barand Posted September 11, 2012 Share Posted September 11, 2012 while(list($key, $val) = each($_POST['need_delete'])) { $sql = "DELETE FROM $tbl_name WHERE Gbk_Id='$val'"; mysql_query($sql); } There are two DONTS in the above section of code [*]DON'T use $_POST data directly in your queries, cleanse it first [*]DON'T run queries in loops See my reply (#3 in this thread) for a better solution Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1377058 Share on other sites More sharing options...
the-botman Posted September 14, 2012 Author Share Posted September 14, 2012 function Remove_Message() { $Result = "False"; while(list($key, $val) = each($_POST['need_delete'])) { $DbRes = MySqlCmd("DELETE FROM page_guestbook WHERE Gbk_Id='$val'"); } if ($DbRes != "1") { $Result = "Database Error."; } return $Result; } the above code works 100% to delete multiple rows from the database how do i use this code instead? $ids_to_delete = array_filter(array_map('intval', $_POST['need_delete'])); // clean up the post data $sql = "DELETE FROM $tblname WHERE id IN (" . join(',', $ids_to_delete) . ")"; i tried it this way $ids_to_delete = array_filter(array_map('intval', $_POST['need_delete'])); // clean up the post data $DbRes = MySqlCmd("DELETE FROM page_guestbook WHERE id IN (" . join(',', $ids_to_delete) . ")"); but it does not work Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1377841 Share on other sites More sharing options...
PFMaBiSmAd Posted September 14, 2012 Share Posted September 14, 2012 Because your column holding the id's is - Gbk_Id Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1377844 Share on other sites More sharing options...
the-botman Posted September 14, 2012 Author Share Posted September 14, 2012 AT last thanks alot for all your help Quote Link to comment https://forums.phpfreaks.com/topic/268104-guestbook-code-help/page/2/#findComment-1377845 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.