contra10 Posted January 22, 2009 Share Posted January 22, 2009 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 https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/ Share on other sites More sharing options...
contra10 Posted January 22, 2009 Author Share Posted January 22, 2009 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 https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743715 Share on other sites More sharing options...
gevans Posted January 22, 2009 Share Posted January 22, 2009 I don't understand yor problem using header('Location: '); This would be the obvious solution Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743779 Share on other sites More sharing options...
contra10 Posted January 23, 2009 Author Share Posted January 23, 2009 so i thought but i get this Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\file11786.php:172) in C:\wamp\www\inbox\index.php on line 108 Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743844 Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 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 https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743849 Share on other sites More sharing options...
contra10 Posted January 23, 2009 Author Share Posted January 23, 2009 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 https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743932 Share on other sites More sharing options...
rubing Posted January 23, 2009 Share Posted January 23, 2009 <?php ob_start(); //insert code //call this wherever the program exits ob_end_flush(); ?> Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743944 Share on other sites More sharing options...
contra10 Posted January 23, 2009 Author Share Posted January 23, 2009 i tried that above...still the same error... ieven tried it with just the ob_start...no luck Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743981 Share on other sites More sharing options...
rubing Posted January 23, 2009 Share Posted January 23, 2009 Post your new code Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743984 Share on other sites More sharing options...
haku Posted January 23, 2009 Share Posted January 23, 2009 ob_start() is a band-aid for code that has not been organized well. You should restructure your code so that any headers are done before any output to the browser rather than using ob_start(). Link to comment https://forums.phpfreaks.com/topic/142028-solved-inbox-on-delete/#findComment-743989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.