Jump to content

help with SQL query


unsider

Recommended Posts

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

$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

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.