Jump to content

Recommended Posts

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;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/115386-solved-delete-records/
Share on other sites

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?

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.