Wintergreen Posted September 3, 2006 Share Posted September 3, 2006 I made a pretty simple blog over the past few days, but have had one problem. I have the page where you write your post, and then you submit it which takes you to the php page that processes the info, adds it to the db etc. However, when I try to use header("location: index.php"); at the end of the db insertions I get this error:Warning: Cannot modify header information - headers already sent by (output started at /home/.alias/synergistic/potentiates.com/pandafactory/addcomment.php:16) in /home/.alias/synergistic/potentiates.com/pandafactory/addcomment.php on line 34The code for the page is here:[code]<?$postid = $_GET['id'];echo "<a href=comment.php?id=" . $postid . ">Your comment has been added, go see it!</a>";include 'db.php';$post_body = $_POST['bodytext'];$post_time = date("Y-m-d H:i:s");$poster_name = $_SESSION['screenname'];$sql = "SELECT comment_number FROM posts WHERE postid = '$postid'";$query = mysql_query($sql);while($row = mysql_fetch_assoc($query)){ $addposts = $row['comment_number'] + 1;}mysql_query("UPDATE posts SET comment_number = '$addposts' WHERE postid = '$postid'") or die(mysql_error());//Enter info into the dbmysql_query("INSERT INTO comments (postid, post_body, post_time, poster_name) VALUES('$postid','$post_body','$post_time','$poster_name')") or die(mysql_error());header("Location: index.php");exit();?>[/code]So, instead of using the header I put up a simple anchor link to the index page above the php processing so the users can click it to go back, but this isn't an ideal solution. The other problem when how I'm currently doing it is if you refresh while on the processing page you end up with double posts. How can I stop this from happening?My other question concerns a page I'm making to manage posts with forms instead of using SSH to manually doing it. My idea was to list each post within a form, each post having a corresponding checkbox that you'd check if you wanted the post deleted, etc. So if you wanted five posts deleted, you'd check the five, click submit and on the next page it would ask one last time if you want to continue and then actually delete them. Now, the problem is that I know how to check for values on the checkboxes, but how do I pass postid of the post to be deleted to the next page? When I set up pages for editing it was easier, because the link to the edit page was edit.php?id=postid, but when I don't know which posts are the ones the user will want to delete this method seems like it doesn't work. Anyway, any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 3, 2006 Share Posted September 3, 2006 [code]<?php$postid = $_GET['id'];echo "<a href=comment.php?id=" . $postid . ">Your comment has been added, go see it!</a>";include 'db.php';$post_body = $_POST['bodytext'];$post_time = date("Y-m-d H:i:s");$poster_name = $_SESSION['screenname'];$sql = "SELECT comment_number FROM posts WHERE postid = '$postid'";$query = mysql_query($sql);while($row = mysql_fetch_assoc($query)){ $addposts = $row['comment_number'] + 1;}if($_POST['submit']){mysql_query("UPDATE posts SET comment_number = '$addposts' WHERE postid = '$postid'") or die(mysql_error());//Enter info into the dbmysql_query("INSERT INTO comments (postid, post_body, post_time, poster_name) VALUES('$postid','$post_body','$post_time','$poster_name')") or die(mysql_error());header("Location: index.php");exit();}?>[/code] Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 3, 2006 Author Share Posted September 3, 2006 I'm still getting the same error as before with the if($_POST['submit']) added in Quote Link to comment Share on other sites More sharing options...
Demonic Posted September 3, 2006 Share Posted September 3, 2006 meaning this script has to be before your HTMLmysql_query("INSERT INTO comments (postid, post_body, post_time, poster_name) VALUES('$postid','$post_body','$post_time','$poster_name')") or die(mysql_error());header("Location: index.php");exit();}?>hence the headers cant be sent again so just replace the header("Location: index.php");withecho "<meta http-equiv=\"refresh\" content=\"2;url=http://webdesign.about.com\">";[code]<?php$postid = $_GET['id'];echo "<a href=comment.php?id=" . $postid . ">Your comment has been added, go see it!</a>";include 'db.php';$post_body = $_POST['bodytext'];$post_time = date("Y-m-d H:i:s");$poster_name = $_SESSION['screenname'];$sql = "SELECT comment_number FROM posts WHERE postid = '$postid'";$query = mysql_query($sql);while($row = mysql_fetch_assoc($query)){ $addposts = $row['comment_number'] + 1;}if($_POST['submit']){mysql_query("UPDATE posts SET comment_number = '$addposts' WHERE postid = '$postid'") or die(mysql_error());//Enter info into the dbmysql_query("INSERT INTO comments (postid, post_body, post_time, poster_name) VALUES('$postid','$post_body','$post_time','$poster_name')") or die(mysql_error());echo "<meta http-equiv=\"refresh\" content=\"2;url=http://webdesign.about.com\">";exit();}?>[/code] Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 4, 2006 Author Share Posted September 4, 2006 Alright, thanks for the reply, it now works without problems, no double posts either.Anyone have any ideas on the form value passing? Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 4, 2006 Author Share Posted September 4, 2006 Bump, I'm sure someone has an idea of how it might be possible Quote Link to comment 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.