Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/183898-help-with-an-if-statement-and-count/
Share on other sites

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 { 

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.

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.

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>					

						";}
						?>

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.