KDM Posted January 6, 2011 Share Posted January 6, 2011 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 More sharing options...
smerny Posted January 6, 2011 Share Posted January 6, 2011 do you have session_start() at the top? you can always try echoing the variable to see if there is actually anything there Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155767 Share on other sites More sharing options...
coupe-r Posted January 6, 2011 Share Posted January 6, 2011 if($_POST['submit']){ if($_POST['$_SESSION['username']))==''){ } Try taking out the ' before $_SESSION[] Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155777 Share on other sites More sharing options...
Rifts Posted January 6, 2011 Share Posted January 6, 2011 also there is no closing ] in this line if($_POST['$_SESSION['username']))==''){ Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155800 Share on other sites More sharing options...
coupe-r Posted January 6, 2011 Share Posted January 6, 2011 Yea.. That's all f'd Do this if($_POST['submit']) { if($_POST[$_SESSION['username'] == '') { } } if($_POST['$_SESSION['username']))==''){ Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155806 Share on other sites More sharing options...
KDM Posted January 6, 2011 Author Share Posted January 6, 2011 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 https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155888 Share on other sites More sharing options...
Zurev Posted January 6, 2011 Share Posted January 6, 2011 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 https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155889 Share on other sites More sharing options...
smerny Posted January 7, 2011 Share Posted January 7, 2011 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? Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155951 Share on other sites More sharing options...
Zurev Posted January 7, 2011 Share Posted January 7, 2011 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 https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155952 Share on other sites More sharing options...
darth_tater Posted January 7, 2011 Share Posted January 7, 2011 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! Link to comment https://forums.phpfreaks.com/topic/223595-trouble-with-a-simple-comment-form/#findComment-1155960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.