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
https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/
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

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"]])) {

Also, don't just echo variables.  use the command

 

var_dump($variable);

 

 

that will give you a TON more information about the particular variable you're trying to access.  It is super useful for debugging the content of arrays!

 

 

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.