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'); } } ?> Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/ 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. Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/#findComment-488271 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. Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/#findComment-488276 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. Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/#findComment-488297 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 Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/#findComment-488300 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()' )"; Link to comment https://forums.phpfreaks.com/topic/95330-help-with-sql-query/#findComment-488301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.