Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Verifying something is in SESSION or POST

Posted on 2008-06-13
3
Medium Priority
?
189 Views
Last Modified: 2010-04-21
Hello,

I am using some simple validators to make sure a variable is entered in an input field, i am also using a couple simple validations to make sure a couple fields match.  Where I'm running into an issue, in the below snip of code i feel like something is missing, it seemed to work for a minute, than when i was working with errors messages all hell broke loose, can you please tell me if this is the correct way to verify there is something typed into this field?
// is this first part the right way to check if there is an entry in this field?
 
if ($_POST['email']) {
}
  else {
      $error_msg .= "Please provide your email address" . "<br />"; 
} 
 
// on the same field i am running this later in the script
 
if ($_POST['email'] === $_POST['vemail']){ //AND check_email($_POST['email'])){
      $_SESSION['email']=$_POST['email'];
} else {
      $error_msg .= "E-mail Addresses do not match" . "<br />";      
}

Open in new window

0
Comment
Question by:vrmetro
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
jml948 earned 1000 total points
ID: 21781895
i use this format when checking a field for an entry


if (isset($_POST['email']) && $_POST['email'] != "") {
}
  else {
      $error_msg .= "Please provide your email address" . "<br />"; 
}
 
if ($_POST['email'] == $_POST['vemail']){ // here i would change "===" to "=="
      $_SESSION['email']=$_POST['email'];
} else {
      $error_msg .= "E-mail Addresses do not match" . "<br />";      
}

Open in new window

0
 

Author Comment

by:vrmetro
ID: 21782222
ok, can you tell me what the difference between == and === is?
0
 

Author Closing Comment

by:vrmetro
ID: 31467041
good solution, going to keep the === because more strict.
but thank you very much.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question