Jump to content

DOUBLE INSERT


kleb

Recommended Posts

please help me with this.since i started posting this form to its self it has been inserting values twice into the database when the user clicks submit button and i also noticed that i have to refresh the page before inserted comments can be showed.this is my code:

<?php
                                 include"header.php";
                                  $sql="SELECT post_content,post_by FROM post WHERE topicsID='$tpid'";
                            $result=mysql_query($sql)or die(mysql_error());
                                while($row=mysql_fetch_array($result))
                             {

                               echo"<strong>{$row['post_by']}</strong>:  {$row['post_content']}"."</br>";
                             }
                                         ?></td>

				</tr>
				</table>
		<?php
include"header.php";
if(isset($_POST['submit']))
{
$comment=mysql_real_escape_string(trim($_POST['comment']));
$name=mysql_real_escape_string(trim($_POST['name']));
$hidden=$_POST['id'];
if($comment!=='' && $name!=='')
{
$topicid=$_GET['id'];
$ins="INSERT INTO post(post_content,post_by,post_id)VALUES('$comment','$name','$topicid')";
mysql_query($ins) or die(mysql_error());
}
else
{
echo"you cannot post an empty field";
}
}


?>
			<h3>Post your comments here</h3>
			<form action=''method='post'>
				<textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea>
				<br />	
				Name:<input type="text"name="name"/> 		
				<input class="button" type="submit"name="submit"value="submit" />

				</p>		
			</form>	

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.