unsider Posted March 10, 2008 Share Posted March 10, 2008 My DB has these 4 feilds: 'id', 'username', 'commenttext', 'commentdate' The username = the current $session->username The commenttext = the $_POST['commenttext'] The commentdate = NOW() My form action, etc.. is all working properly, I just need to fix this query that inputs the info in the DB and I'm set. Thanks. <?php // HELP FROM HERE if(isset($_POST['commenttext'])) { $commenttext = $_POST['commenttext']; $username = $session->$username; $sql="INSERT INTO comments VALUES ('$username','$commenttext', 'NOW()')"; // TO HERE if (!@mysql_query($sql)) { echo 'Error adding query: ' . mysql_error(); header('main.php'); } } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 $session->username instead of $session->$username ? It's a good idea to print out $sql too, so you can see what query you are running. That fixes a LOT of errors. Quote Link to comment Share on other sites More sharing options...
unsider Posted March 10, 2008 Author Share Posted March 10, 2008 $session->username instead of $session->$username ? It's a good idea to print out $sql too, so you can see what query you are running. That fixes a LOT of errors. Ooops, wow, well I tested it without the $ on username. Not sure how it got in there, although I think I tried a new method before resorting to questions. I think my query just needs some effective rewriting. Quote Link to comment Share on other sites More sharing options...
unsider Posted March 10, 2008 Author Share Posted March 10, 2008 I'm going to bed, but if anyone wants to help me out, I'd really apreciate it. G'nite all. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 10, 2008 Share Posted March 10, 2008 Show us the output of "echo $sql;" and we may be able to help Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 10, 2008 Share Posted March 10, 2008 try this $sql="INSERT INTO `comments` (username, commenttext, commentdate) VALUES ( '$username','$commenttext', 'NOW()' )"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.