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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.