andrew_biggart Posted December 3, 2009 Share Posted December 3, 2009 Ok what I am trying to do is when ever a user has added a comment i want it to echo "ur comment has been added" but only if count is 1. If i post hasnt been submitted and count =0 then i dont want it to echo anything. Im trying to wrap the if statment around an if statement but cannot seem to get it working. Can anyone help please? <?php $username=$_GET['username']; $Count=$_GET['Count']; if($Count=1) { echo"Your comment has been added"; if(isset($_SESSION['myusername'])) { echo " <a name='Profile_comment' id='Profile_comment'></a> <form method='post' action='profile_comment.php?username=$username'> <table class='replies_table' style='width: 340px; border-style: solid' align='center'> <tr><td class='reply'>Add a profile comment</td></tr> <tr><td class='replies' colspan='2'> <textarea class='replycomment'name='profilecomment' style='width: 321px; height: 34px'></textarea> </td></tr> <tr><td style='width: 50%' class='repliesh'>Max 200 characters</td> <td class='style3'> <input name='Submit1' type='submit' value='Add Comment' /> </td></tr> </table> </form> "; } else{ } } else{ } ?> After the comment has been submitted the url will look like this. http://localhost/profile.php?username=AdMiN&Count=1#Profile_comment Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/ Share on other sites More sharing options...
Alex Posted December 3, 2009 Share Posted December 3, 2009 = is the assignment operator, you need to use the comparison operator ==. if($Count==1) Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970791 Share on other sites More sharing options...
andrew_biggart Posted December 3, 2009 Author Share Posted December 3, 2009 Ok thanks I should of realised that myself! Now the problem is that the form to enter the comment doesnt show up? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970795 Share on other sites More sharing options...
mikesta707 Posted December 3, 2009 Share Posted December 3, 2009 Do you have session_start() at the beginning of the page? Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970798 Share on other sites More sharing options...
andrew_biggart Posted December 3, 2009 Author Share Posted December 3, 2009 Yes mikesta707 I do Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970799 Share on other sites More sharing options...
mrMarcus Posted December 3, 2009 Share Posted December 3, 2009 does $Count equal 1? these: } else{ } } else{ } do nothing to help when troubleshooting. you need to fill those in so you know where you are in your code. something like: <?php $username = $_GET['username']; $Count= $_GET['Count']; if ($Count=1) { echo"Your comment has been added"; if (isset ($_SESSION['myusername'])) { echo " <a name='Profile_comment' id='Profile_comment'></a> <form method='post' action='profile_comment.php?username=$username'> <table class='replies_table' style='width: 340px; border-style: solid' align='center'> <tr><td class='reply'>Add a profile comment</td></tr> <tr><td class='replies' colspan='2'> <textarea class='replycomment'name='profilecomment' style='width: 321px; height: 34px'></textarea> </td></tr> <tr><td style='width: 50%' class='repliesh'>Max 200 characters</td> <td class='style3'> <input name='Submit1' type='submit' value='Add Comment' /> </td></tr> </table> </form> "; } else { echo 'User not set.'; } } } else { echo '$Count not equal to 1.'; } ?> would be better, as A. indenting your code makes it much easier to read when looking for errors, etc., and B. you have finished your conditions which will allow you to understand/know where your code is at. obviously, you can enter whatever you like in the } else { Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970801 Share on other sites More sharing options...
andrew_biggart Posted December 3, 2009 Author Share Posted December 3, 2009 Ok thankyou very much for your help, i will try and get into the habit of doing this. The form does show up when count=1 but i want the form always to show up wether count =1 or not! I only want the echo to show up when ever count =1 to say u have submitted a comment. Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970809 Share on other sites More sharing options...
mrMarcus Posted December 3, 2009 Share Posted December 3, 2009 sorry, i copied your original code which still had: if ($Count=1) which i should've fixed as per mikesta's comment. you need to remove the form from your IF statement then. pretty simple. anything you want showing only if $Count is equal to 1, have it in that condition, otherwise, remove it. Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970814 Share on other sites More sharing options...
mrMarcus Posted December 3, 2009 Share Posted December 3, 2009 simply do: if ($Count==1) { echo"Your comment has been added"; } //form, etc., goes here... EDIT: did it again .. $Count == 1 NOT $Count=1 .. lol Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970817 Share on other sites More sharing options...
andrew_biggart Posted December 3, 2009 Author Share Posted December 3, 2009 Ok problem solved. Thankyou mrMarcus it was your suggestion of adding echos to the else statements that made me realise what the problem was. I will get myself into the habit of doing this from now on. Thanks everyone that helped. For anyone that is intrested this is how I got it working <?php $username=$_GET['username']; $Count=$_GET['Count']; if($Count==1) { echo"Your comment has been added"; if(isset($_SESSION['myusername'])) { echo " <a name='Profile_comment' id='Profile_comment'></a> <form method='post' action='profile_comment.php?username=$username'> <table class='replies_table' style='width: 340px; border-style: solid' align='center'> <tr><td class='reply'>Add a profile comment</td></tr> <tr><td class='replies' colspan='2'> <textarea class='replycomment'name='profilecomment' style='width: 321px; height: 34px'></textarea> </td></tr> <tr><td style='width: 50%' class='repliesh'>Max 200 characters</td> <td class='style3'> <input name='Submit1' type='submit' value='Add Comment' /> </td></tr> </table> </form> "; } else{ echo"User not logged in";} } else{ echo " <a name='Profile_comment' id='Profile_comment'></a> <form method='post' action='profile_comment.php?username=$username'> <table class='replies_table' style='width: 340px; border-style: solid' align='center'> <tr><td class='reply'>Add a profile comment</td></tr> <tr><td class='replies' colspan='2'> <textarea class='replycomment'name='profilecomment' style='width: 321px; height: 34px'></textarea> </td></tr> <tr><td style='width: 50%' class='repliesh'>Max 200 characters</td> <td class='style3'> <input name='Submit1' type='submit' value='Add Comment' /> </td></tr> </table> </form> ";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/#findComment-970825 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.