ricerocket Posted February 12, 2008 Share Posted February 12, 2008 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... Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/ Share on other sites More sharing options...
cooldude832 Posted February 12, 2008 Share Posted February 12, 2008 look at the operators on php.net http://us3.php.net/manual/en/language.operators.php == is probably what you want Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464486 Share on other sites More sharing options...
ricerocket Posted February 12, 2008 Author Share Posted February 12, 2008 ok so the code I created will work it just needs to use == ? Thats what I was stuck on and I couldn't figure out why I couldn't get it to do what I wanted. Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464487 Share on other sites More sharing options...
cooldude832 Posted February 12, 2008 Share Posted February 12, 2008 = will define $var = "This value"; == is a comparisons (read on operators for specifically on its compare mode) and returns TRUE or FALSE on success. Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464488 Share on other sites More sharing options...
ricerocket Posted February 12, 2008 Author Share Posted February 12, 2008 ok so if that is what I need would I use $a == $b for equal variables or $a === $b for identical variables? because the passwords must match for it to not give an error Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464490 Share on other sites More sharing options...
cooldude832 Posted February 12, 2008 Share Posted February 12, 2008 === 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? Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464491 Share on other sites More sharing options...
ricerocket Posted February 12, 2008 Author Share Posted February 12, 2008 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? Link to comment https://forums.phpfreaks.com/topic/90591-how-do-i-verify-that-certain-variables-match/#findComment-464494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.