Jump to content

Recommended Posts

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

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();

i get this error whe i try to post:

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"?

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.