1,105,340 Community Members

isset $_POST troubles

Member Avatar
majoorpa
Newbie Poster
2 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am a newbie to php. I am simply trying to validate input from a login page. However I am always getting a positive boolean value when username is entered or not. Following is my code for the login page;

<form method = "post" action = "entering.php">
LOGIN <br />
<br />
User Name: <input type = "text" size = "10" id = "username" name = "username" /><br /><br />
Password: <input type = "password" size = "10" id = "password" name = "password"/><br />
<br />
<br />
<input type = "submit" value = "Submit" /> &nbsp <input type = "reset" />
</form>
</body>

</html>

Following the code for my action php page ie. entering.php

<?php


If (isset($_POST['username']))
	{
	echo "Username Entered"."<br />";
	
	}
Else
	{
	echo "Username Not entered"."<br />";
	}
?>

And I always get the message "Username Entered" even if the username is not entered.

Can any one help?

Member Avatar
somedude3488
Nearly a Posting Virtuoso
1,354 posts since Jun 2007
Reputation Points: 228 [?]
Q&As Helped to Solve: 202 [?]
Skill Endorsements: 7 [?]
 
0
 

sometimes i found that the form will submit the field with nothing and add it to post array. you need to check and make sure the username is also not empty. you can do this by comparing it to an empty string or use the empty() function.
example:

if ( isset( $_POST['username'] ) && $_POST['username'] !== '' ) {
  echo 'Username Entered<br />';
}
else {
  echo 'Username Not Entered<br />';
}
Member Avatar
almostbob
Nearly a Senior Poster
3,381 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 424 [?]
Skill Endorsements: 14 [?]
 
0
 

Why not echo $username and see what is being posted

<?php
if isset($username) {echo $username; }
If (isset($_POST['username']))
 { echo $username."was posted";
 echo "Username Entered"."<br />"; }
Else  { echo $username."was posted";
 echo "Username Not entered"."<br />"; }
?>
Member Avatar
majoorpa
Newbie Poster
2 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you very much for a quick response. It solved the issue. I used the empty() function along with isset() function. It did solve the issue as said.

Question Answered as of 5 Years Ago by somedude3488 and almostbob
senthil.nila
Newbie Poster
1 post since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

isset means??

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article