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
https://forums.phpfreaks.com/topic/256033-double-insert/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.