dachshund Posted August 25, 2009 Share Posted August 25, 2009 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 More sharing options...
alexdemers Posted August 25, 2009 Share Posted August 25, 2009 Nothing wrong with that code. What's in your header.php file? Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906051 Share on other sites More sharing options...
dachshund Posted August 25, 2009 Author Share Posted August 25, 2009 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> Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906053 Share on other sites More sharing options...
dachshund Posted August 25, 2009 Author Share Posted August 25, 2009 and when i do: $sql="INSERT INTO `comments` (`userid`, `comment`) VALUES ('$session_name', '$commentsbox');"; it only ads the enters data into the 'comment' column on the first post it creates. Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906085 Share on other sites More sharing options...
dachshund Posted August 25, 2009 Author Share Posted August 25, 2009 help! this is driving me mad Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906098 Share on other sites More sharing options...
mikesta707 Posted August 25, 2009 Share Posted August 25, 2009 I'm not sure you are supposed to have a semi-colon at the end of SQL queries but I might be wrong... Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906099 Share on other sites More sharing options...
dachshund Posted August 25, 2009 Author Share Posted August 25, 2009 yeah i got rid of that but still the same. Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906183 Share on other sites More sharing options...
dachshund Posted August 25, 2009 Author Share Posted August 25, 2009 any way to fix this anyone? it's got me stumped Link to comment https://forums.phpfreaks.com/topic/171831-posts-into-database-twice/#findComment-906200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.