Jump to content

Trouble with a simple comment form


KDM

Recommended Posts

I'm trying to modify my existing comment form to only allow users to post comments.  Right now anyone can visit the site and comment.

 

Here is my code

if($_POST['submit']){
if($_POST['$_SESSION['username']))==''){
	$err = "You must login first";
}elseif($_POST['thecomment']==''){
	$err = "You have to enter a comment.";
}else{
	$username = strip_tags($_POST['username']);	
	$themessage = strip_tags($_POST['thecomment']);	
	$ezdb->get_results("INSERT INTO user_comments (id,date_added, posted_by, message, image_id) VALUE ('','".time()."','".$name."','".$themessage."','".$imageid."')");
	$err = "Thank you for your comment.";
}	
}

 

 

When a user is logged in, I still get the "you must log in error"  Help please.

Link to comment
Share on other sites

Yea..  That's all f'd

 

Do this

 

if($_POST['submit']) {

 

    if($_POST[$_SESSION['username'] == '') {

 

          }

}

 

 

 

if($_POST['$_SESSION['username']))==''){

 

I received this error when tyring that

Parse error: syntax error, unexpected ')', expecting ']' in /home/content/13/6987913/html/imagedetails.php on line 15

Link to comment
Share on other sites

Yea..  That's all f'd

 

Do this

 

if($_POST['submit']) {

 

    if($_POST[$_SESSION['username'] == '') {

 

          }

}

 

 

 

if($_POST['$_SESSION['username']))==''){

 

I received this error when tyring that

Parse error: syntax error, unexpected ')', expecting ']' in /home/content/13/6987913/html/imagedetails.php on line 15

 

Change that last line to:

if (empty($_POST[$_SESSION["username"]])) {

Link to comment
Share on other sites

i didnt notice that before..

 

shouldn't

 

$_POST['$_SESSION['username']']

 

just be

 

$_SESSION['username']

 

? i'm guessing you don't have an input named after the username?

 

That is correct, just check for the session.

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.