Jump to content

posts into database twice


dachshund

Recommended Posts

Hi,

 

I'm just trying to enter the user's id into a comments table when they post a comment. but it's posting it in twice each time.

 

any ideas why?


<?php
include "template/header.php";

if($_SESSION['uid']){
$userid=$_SESSION['uid'];

$sql="INSERT INTO `comments`(`userid`) VALUES ('$userid');";
$result=mysql_query($sql) or die(mysql_error());

if($result){
echo "Successful\n";
}
else {
echo "ERROR\n";
}
	}else {
	session_destroy();
	echo "You must be logged in to add a comment.\n";
	}

?>

<?php

include "template/footer.php";

?>

 

Link to comment
https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/
Share on other sites

this is my header.php

 


<?php
   session_start();
   
   $connect= mysql_connect ("", "", "") or die(mysql_error());
   $db = mysql_select_db ("", $connect);
   
   $session_name = $_SESSION['uid'];
   
   
?>

<head>
<script type="text/javascript" src="/phptesting/csspopup.js"></script>
<link href="/phptesting/template/stylesheet.css" rel="stylesheet" type="text/css" />
<title></title>
</head>

<body marginheight="0">



<div id="site_container">


<!-- sign up -->
<div id="toolbar">
<div id="follow">
<ul>
    <li><img src="/facebook_icon.png"></li>
    <li><img src="/twitter_icon.png"></li>
    <li><img src="/myspace_icon.png"></li>
    <li><img src="/rss_icon.png"></li>
    </ul>
</div>

<ul>
<li>

<?php
   if($session_name){
      echo "<span class=\"login_text\"><a href=\"/phptesting/account/\">ACCOUNT</a> | <a href=\"/phptesting/logout.php\">LOGOUT</a></span>\n";
   }else {
   ?>
   
<?php

include $_SERVER['DOCUMENT_ROOT'] . "/phptesting/template/loginform.php";

?>
</li>
<li>
<?php

include $_SERVER['DOCUMENT_ROOT'] . "/phptesting/register.php";

   }

?>
<li>
<form action="/phptesting/search.php" method="get" class="search_text" name="search" id="searchform" >
  <input type="text" size="30" class="search_text" value="SEARCH" name="q" onFocus="if(!this._haschanged){this.value=''};this._haschanged=true;"/>
</form>
</li>
</ul>
</div>


<!-- end -->

<div class="clear"></div>

<div id="header">

HUH. Magazine

</div>

<!-- Navigation -->
<div id="navigation">
<ul>
<li><a href="/phptesting/">Home</a></li>
<li><a href="/phptesting/feature/">Features</a></li>
<li><a href="#">Interviews</a></li>
    <li><a href="#">Reviews</a></li>
    <li><a href="#">Blog</a></li>
    <li><a href="#">Shop</a></li>
    <li><a href="#">TV</a></li>
</ul>
</div>

<div class="clear"></div>

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.