andrew_biggart Posted February 18, 2010 Share Posted February 18, 2010 Ok what I am trying to do is create a script which first checks if the user is logged in, if they are display a comment form if they are not do not display the form. Next once that has been checked I want to check if the user has submitted the form, if they have run the insert mysql statement and if they havnt do nothing. I have messed about with it so much and I can get certain parts working but not others, Please help me get my head around it... Here is what I have. <?php if(isset($_SESSION['myusername'])) { echo " <form method='post' action='#Profile_comment'> <table class='pro_addcomment'> <tr> <td class='pro_add_h' colspan='3'>Add a profile comment</td> </tr> <tr> <td class='pro_add_text' colspan='2'> <textarea name='profilecomment' class='pro_add_input'></textarea> </td> <td rowspan='2' class='pro_view_pic' valign='top'> <img src='../Profile_pics/". $image ."' style='width:50px; height:50px;' /> </td> </tr> <tr> <td class='pro_add_max'>Max 200 characters</td> <td class='pro_add_button'> <input class='acc_alerts_accept' name='add_comment' type='submit' value='Add Comment' /> </td> </tr> </table> </form> "; if(isset($_POST['add_comment'])){ include("config.php"); $Comment_user=$_GET['username']; $Comment_sender=$_SESSION['myusername']; $Comment_comment=$_POST['profilecomment']; $Profile_picture=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_profile_comments_tempt (Comment_user, Comment_sender, Comment_date, Comment_content, Profile_picture)VALUES('$Comment_user','$Comment_sender', NOW(),'$Comment_comment', '$Profile_picture')"; $result=mysql_query($sql); if($result){ header("location:profile.php?username=$Comment_user#Profile_comment"); } else{ } } else{ echo"<h1 class=status_red>Please Login to submit a comment!</h1>"; } ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted February 18, 2010 Share Posted February 18, 2010 ...and I can get certain parts working but not others... Care to share which bits are working and which bits aren't? Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted February 18, 2010 Author Share Posted February 18, 2010 Well at the minute im getting a syntax error which I cannot spot, and then i can test it and let you know Quote Link to comment Share on other sites More sharing options...
andrew_biggart Posted February 18, 2010 Author Share Posted February 18, 2010 ok sorted the syntax error, but now even when i am logged in it shows the form but also the the you need to be logged in echo. And also the second if statement is not working. Hear is the new code. <?php if(isset($_SESSION['myusername'])) { echo " <form method='post' action='#Profile_comment'> <table class='pro_addcomment'> <tr> <td class='pro_add_h' colspan='3'>Add a profile comment</td> </tr> <tr> <td class='pro_add_text' colspan='2'> <textarea name='profilecomment' class='pro_add_input'></textarea> </td> <td rowspan='2' class='pro_view_pic' valign='top'> <img src='../Profile_pics/". $image ."' style='width:50px; height:50px;' /> </td> </tr> <tr> <td class='pro_add_max'>Max 200 characters</td> <td class='pro_add_button'> <input class='acc_alerts_accept' name='add_comment' type='submit' value='Add Comment' /> </td> </tr> </table> </form> "; if(isset($_POST['add_comment'])){ include("config.php"); $Comment_user=$_GET['username']; $Comment_sender=$_SESSION['myusername']; $Comment_comment=$_POST['profilecomment']; $Profile_picture=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_profile_comments_tempt (Comment_user, Comment_sender, Comment_date, Comment_content, Profile_picture)VALUES('$Comment_user','$Comment_sender', NOW(),'$Comment_comment', '$Profile_picture')"; $result=mysql_query($sql); if($result){ header("location:profile.php?username=$Comment_user#Profile_comment"); } else{ } } else{ echo"<h1 class=status_red>Please Login to submit a comment!</h1>"; } } ?> Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 Try this. also in Header(); use a full path to url. <?php if(isset($_SESSION['myusername'])) { echo " <form method='post' action='#Profile_comment'> <table class='pro_addcomment'> <tr> <td class='pro_add_h' colspan='3'>Add a profile comment</td> </tr> <tr> <td class='pro_add_text' colspan='2'> <textarea name='profilecomment' class='pro_add_input'></textarea> </td> <td rowspan='2' class='pro_view_pic' valign='top'> <img src='../Profile_pics/".$image."' style='width:50px; height:50px;' /> </td> </tr> <tr> <td class='pro_add_max'>Max 200 characters</td> <td class='pro_add_button'> <input class='acc_alerts_accept' name='add_comment' type='submit' value='Add Comment' /> </td> </tr> </table> </form> "; if(isset($_POST['add_comment'])){ include("config.php"); $Comment_user=$_GET['username']; $Comment_sender=$_SESSION['myusername']; $Comment_comment=$_POST['profilecomment']; $Profile_picture=$_SESSION['myavatar']; $sql="INSERT INTO biggartfp9_profile_comments_tempt (Comment_user, Comment_sender, Comment_date, Comment_content, Profile_picture)VALUES('$Comment_user','$Comment_sender', NOW(),'$Comment_comment', '$Profile_picture')"; $result=mysql_query($sql); if($result){ header("Location: profile.php?username=$Comment_user#Profile_comment"); } else{ } } else{ echo"<h1 class=status_red>Please Login to submit a comment!</h1>"; } } ?> Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 echo $_SESSION['myusername']; post result Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.