AviNahum Posted November 25, 2008 Share Posted November 25, 2008 hey {sorry for very poor English, i from israel} so i made comments system for my web, all works fine! but there is a one problem. for example: if you post a comment it added to DB but to see the comment that you post you need to refresh the page. how i can do that show the comment straight after you post it? (it's alredy connected to DB) <form action="<?php echo $_SERVER['REQUEST_URI']."&act=send"; ?>" method="POST"> name:<br> <input type="text" size="25" name="name" maxlength="25"><br> <textarea cols="50" rows="5" name="reply"></textarea> <br> <input type="submit" value="post"> </form> <?php if ($_GET['act'] == "send") { if (!$_POST['name'] OR !$_POST['reply']) { echo "<script language='javascript'> alert('ERROR: data missing') </script>"; } else { $name = htmlspecialchars("$_POST[name]", ENT_QUOTES); $reply = htmlspecialchars("$_POST[reply]", ENT_QUOTES); $date = date("j/n/Y", time() ); $query = mysql_query("INSERT INTO web_downloads_replies ( name, content, date, reply_in ) VALUES ( $name , '$reply' , '$date' , '$download_id' )"); } } } ?> thanks! Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/ Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 So what is the actual problem? Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698690 Share on other sites More sharing options...
AviNahum Posted November 25, 2008 Author Share Posted November 25, 2008 how i can do that show the comment straight after you post it? Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698697 Share on other sites More sharing options...
JonnoTheDev Posted November 25, 2008 Share Posted November 25, 2008 After the insert query reload the page using the header function $query = mysql_query("INSERT INTO web_downloads_replies ( name, content, date, reply_in ) VALUES ( $name , '$reply' , '$date' , '$download_id' )"); // reload page header("Location:nameofyourpage.php"); exit(); Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698700 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Header won't work, use a HTML redirect instead. Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698708 Share on other sites More sharing options...
AviNahum Posted November 25, 2008 Author Share Posted November 25, 2008 i get this error whe i try to post: Quote Warning: Cannot modify header information - headers already sent by (output started at /home/user/domains/mydomain/public_html/db_connect.php:11) in /home/user/domains/mydomain/public_html/download.php on line 204 its the db_connect.php file: <?php $db = 'myDB'; $username = 'myUser'; $password = 'myPass'; $host = 'myHost'; $DB = mysql_pconnect("$host" , "$username" , "$password") or die(mysql_error()); mysql_select_db("$db",$DB) or die(mysql_error()); ?> revraz, what you mean when you say "HTML redirect instead"? Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698711 Share on other sites More sharing options...
JonnoTheDev Posted November 25, 2008 Share Posted November 25, 2008 Place your insert code above any html or echo/print statement (very top of script). i.e. if ($_GET['act'] == "send") { // insert post // reload page header("Location:) exit(); } <form ....... </form> Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698720 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Just use a HTML redirect... as stated.. Link to comment https://forums.phpfreaks.com/topic/134226-problem-with-comments-system/#findComment-698721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.