Jump to content

[SOLVED] inbox on delete


contra10

Recommended Posts

i'm trying to be able to delete a message and still be redirected to the same page...I tried the header() function but i aleready have it set in my header.php...when i run this code i can transfer back to my inbox.php but the userid is no longer in the url so the first part of the script does not run heres the code

 

<?php

if (isset($_POST['checkbox']) and ($_POST['delete'])) { 

$checkboxid = mysql_real_escape_string($_POST['checkbox']);	
mysql_query("DELETE FROM inbox WHERE iid='$checkboxid'");


?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" width="600" align="left">
<tr><td height="20" width="10%" align="center">Delete</td>
<td>Messages</td></tr>
<br>
<br>
<br>
<br>
<?php
		mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());

if(is_numeric($_GET['user'])){

$id = $_GET['user'];
}


 $friendq= "SELECT * FROM inbox WHERE recid = '$id' ORDER BY iid DESC";
$friendnames = mysql_query($friendq) or die(mysql_error());

while($friend = mysql_fetch_array($friendnames)) 
{ 
$friendid= "{$friend['sendid']}";
$friendusername= "{$friend['recusername']}";
	$sendingusername= "{$friend['sendusername']}";
$date= "{$friend['date']}";
$title= "{$friend['title']}";
	$msgid= "{$friend['iid']}";
 	$colorvalue= "{$friend['value']}"; 

$bgcc=1;

	echo "<tr>";
	echo"<td><Input type = 'Checkbox' Name ='checkbox' value ='$msgid'></td>";
 echo "<td align='left' width='10%' height='50'>";
echo"<a href ='http://localhost/profile/index.php?user=$friendid' ><img src='http://localhost/image/imagereplace.php?id=$friendid'></a>";
  echo "</td>";
	if ($bgcc == $colorvalue){
	echo"<td width= '90%' align='center' bgcolor='#DEDAD7'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}else{
		echo"<td width= '90%' align='center' bgcolor='black'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}
	echo"<FONT FACE='ariel' SIZE='3' color='#0094f7'><b>$title<br><br></font></td></tr>";
	echo "<tr><td></td><td></td>";
	echo "<td align='right' bgcolor='#DEDAD7'><FONT FACE='ariel' SIZE='2' color='#0094f7'>Sent by <b>$sendingusername</b> on $date</font></a></td>";
echo "</tr>";
}
?>
<?php
}else{
	?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="1" width="600" align="left">
<tr><td height="20" width="10%" align="center">Delete</td>
<td>Messages</td></tr>
<br>
<br>
<br>
<br>
<?php
		mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("registration") or die(mysql_error());

if(is_numeric($_GET['user'])){

$id = $_GET['user'];
}


 $friendq= "SELECT * FROM inbox WHERE recid = '$id' ORDER BY iid DESC";
$friendnames = mysql_query($friendq) or die(mysql_error());

while($friend = mysql_fetch_array($friendnames)) 
{ 
$friendid= "{$friend['sendid']}";
$friendusername= "{$friend['recusername']}";
	$sendingusername= "{$friend['sendusername']}";
$date= "{$friend['date']}";
$title= "{$friend['title']}";
	$msgid= "{$friend['iid']}";
 	$colorvalue= "{$friend['value']}"; 

$bgcc=1;

	echo "<tr>";
	echo"<td><Input type = 'Checkbox' Name ='checkbox' value ='$msgid'></td>";
 echo "<td align='left' width='10%' height='50'>";
echo"<a href ='http://localhost/profile/index.php?user=$friendid' ><img src='http://localhost/image/imagereplace.php?id=$friendid'></a>";
  echo "</td>";
	if ($bgcc == $colorvalue){
	echo"<td width= '90%' align='center' bgcolor='#DEDAD7'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}else{
		echo"<td width= '90%' align='center' bgcolor='black'><a style='text-decoration:none' href ='http://localhost/inbox/message.php?msg=$msgid' >";
	}
	echo"<FONT FACE='ariel' SIZE='3' color='#0094f7'><b>$title<br><br></font></td></tr>";
	echo "<tr><td></td><td></td>";
	echo "<td align='right' bgcolor='#DEDAD7'><FONT FACE='ariel' SIZE='2' color='#0094f7'>Sent by <b>$sendingusername</b> on $date</font></a></td>";
echo "</tr>";
}
?>
<input type="submit" name="delete" value="delete">
</table>
</form>
	<?php
	}
?>

Link to comment
Share on other sites

basically after i delete a message...after i click delete that message the message is suppose to disappar and all my other messages should be displayed...instead of now when i delete a message it deletes and i can't view the other messages in the table unless i click back

Link to comment
Share on other sites

The problem is that you're trying to send a header after something has been printed to the screen (sent out by php). You need to do the deletion of the message and send the header before anything is sent out to the client.

 

You have a few options;

 

1. Restructure your code to do just that

 

2. Use ob_start() and it's other functions

Link to comment
Share on other sites

perhaps i don't understand ob_function() fully...in my header file i have two header redirects which i changed to this

<?php
if ($pass != $info['password']) 
{ 
ob_start();
header("Location: http://localhost/"); 
ob_end_flush();
} 
//otherwise they are shown the admin area 
else{
$user = "{$row2['id']}";
$userq = "{$row['username']}";

echo "<a style='text-decoration:none' href='http://localhost/profile/index.php?user=$user'><FONT FACE='ariel' SIZE='2' color='#DEDAD7'><b>$userq</b></FONT></a>";
echo " ";
echo "<a style='text-decoration:none' href='http://localhost/logout/logout.php'><FONT FACE='ariel' SIZE='2' color='#5f5f5f'>Logout</FONT></a>"; 
} 
}
}
else

//if the cookie does not exist, they are taken to the login screen 
{ 
ob_start();
header("Location: http://localhost/"); 
ob_end_flush();
} 
mysql_close();
?>

 

in my inbox file i put this

<?php


if (isset($_POST['checkbox']) and ($_POST['delete'])) { 

$checkboxid = mysql_real_escape_string($_POST['checkbox']);	
mysql_query("DELETE FROM inbox WHERE iid='$checkboxid'");
}
ob_start();
header("Location:http://localhost/inbox/index.php?user=$id");
ob_end_flush();

?>

 

i still get the same problem...i can \t think of a way to redesign my code... as the header is used to detect on every page whether or not a person is logged in via a cookie

Link to comment
Share on other sites

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.