coolphpdude Posted July 18, 2008 Share Posted July 18, 2008 This is a wierd one. (well for me anyway) I have a message section on my uni project. On that page you see row after row of your messages, at the end of each row is a tick box, tick the box of the messages you want to delete and click the 'delete' button. The messages are deleted and the page is refreshed, it works perfectly. I borrowed the code that does this and put it on a different page and its not working properly. This page is the profile of a class, so class details, current work, loads of crap that you don't really need to know about but at the bottom of this class profile page is memo's to this class in date order. Now, i have tried to incorporate the same delete scenario in this page. Tick box after the memo, tick the ones you want to delete and click delete. So back to where i was, i took working code, applied it to this page, changed the relevant settings and half works. The memo deletes... however, the page is not refreshed, its actually blank. Any fields i pull in from the database with regards to the class profile are not showing up, i have to go out of the class profile page and go back into it to see the profile again (minus the deleted memo's). So the code is actually deleting what it is meant to, but where is my page going... Any help?? I'll post my code below, stripped down just with what you need <?php // delete message loop switch(@$_GET["action"]) { Case "delete": if(is_array($_POST['checkbox'])) { foreach($_POST['checkbox'] as $m_id) { mysql_query("DELETE FROM classmemo WHERE m_id='$m_id'") or die(mysql_error()); } } //echo 'records deleted'; //break; default: // form for memo delete echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?action=delete">'; // memo table echo "<table width='400' border='0' cellspacing='0' cellpadding='10'>"; //set number of columns and initial column number $numcols = 3; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT * FROM classmemo WHERE c_id='$c_id"; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_array($mysql_result)) { //get data $memo = $myrow[0]; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } $memo = $myrow["m_id"]; // output row from database echo "<td width='25%' align='center' valign='top'>$memo<input class='blank' name='checkbox[]' type='checkbox' id='checkbox[]' value='".$myrow['m_id']." '></td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<TD></TD>"; echo"</table>"; echo "<br>"; echo "<table width='100%'>"; echo "<tr>"; echo "<td align='left'>"; echo '<input type="submit" value="Delete Pictures" />'."\n"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; //break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/115386-solved-delete-records/ Share on other sites More sharing options...
coolphpdude Posted July 18, 2008 Author Share Posted July 18, 2008 I've figured it out. Cheers anyway. Quote Link to comment https://forums.phpfreaks.com/topic/115386-solved-delete-records/#findComment-593202 Share on other sites More sharing options...
coolphpdude Posted July 18, 2008 Author Share Posted July 18, 2008 Like i said above i've figured out what the problem is. However i cant think of a way around it... The problem is with the structure of the site. As a teacher you get a list of classes, you click a class which sends the class_ID to the display class page, the search queries are carried out using this ID but what must be happening is that when you click the delete button it refreshes the page but doesnt have the ID to be able to do the searches because nothing was being passed this time around. Any1 got any idea how i can get round this? Quote Link to comment https://forums.phpfreaks.com/topic/115386-solved-delete-records/#findComment-593216 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.