Jump to content

How do I verify that certain variables match


ricerocket

Recommended Posts

I'm having trouble doing this and I can't find anything about in online anywhere so I though I would just ask

 

I need to make something that verifies that two post variables match eachother otherwise output an error message such as below:

 

$password = $_POST['password']
$password_confirmation = $_POST['passconfirm']

if ( $password = $password_confirmation ) {
} else { 
$ermsg = "Passwords do not match please go back and try again";
}

 

but I'm not sure how exactly to create this since I'm not very good at php...

=== is a bit more than == and really shouldn't be used unless you find a reason

examples

 

<?php
$var1 = "1";
$var2 = 1;
if($var1 == $var2){
#True
}
if($var1 === $var2){
#false
}
if($var1 == "1"){
#true
}
if($var1 === "1"){
#true
}
if($var1 === 1){
#should be false
}
?>

 

Get it better?

Ok I get it now so I should do something like this:

 

$password = $_POST['password'];
$password_confirmation = $_POST['passconfirm'];

if ( $password != $password_confirmation ) {
$ermsg = "Passwords do not match please go back and try again";
}

 

That way if they're anything but matching it will output the error message. This would work right?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.