[PHP] comparing a string
I have a quiz where the ansers are held in a array called $correct answers. When I compare the string if ($_REQUEST['x']= $correct_answers[$page-1]) { with a double == the answer is always correct with the single = it is always wrong. when I echo out the posted answer and the value from the answers arrray they are correct. echo post equals.$_POST['x']. corect answer is.$correct_answers[$page-1]; Ross -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comparing a string
= is the assignment operator. It is not a comparison. == is the weak equality comparator. === is the strong equality comparator. On Tuesday 20 June 2006 06:43, Ross wrote: I have a quiz where the ansers are held in a array called $correct answers. When I compare the string if ($_REQUEST['x']= $correct_answers[$page-1]) { with a double == the answer is always correct with the single = it is always wrong. when I echo out the posted answer and the value from the answers arrray they are correct. echo post equals.$_POST['x']. corect answer is.$correct_answers[$page-1]; Ross -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it. -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comparing a string
At 12:43 PM +0100 6/20/06, Ross wrote: I have a quiz where the ansers are held in a array called $correct answers. When I compare the string if ($_REQUEST['x']= $correct_answers[$page-1]) { with a double == the answer is always correct with the single = it is always wrong. when I echo out the posted answer and the value from the answers arrray they are correct. When you say == the answer is always correct -- does that mean even when the answer is wrong? If so, then there's something else going on here. But, I believe the answer is: if ($_REQUEST['x'] == $correct_answers[$page-1]) { This will compare the two and if they are the same will report true. You should read the manual. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] comparing a string
When the $_REQUEST['x'] is not 0 or '', it will be always correct condition of your if. see the magic*. -Original Message- From: tedd [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 20, 2006 10:02 PM To: Ross; php-general@lists.php.net Subject: Re: [PHP] comparing a string At 12:43 PM +0100 6/20/06, Ross wrote: I have a quiz where the ansers are held in a array called $correct answers. When I compare the string if ($_REQUEST['x']= $correct_answers[$page-1]) { with a double == the answer is always correct with the single = it is always wrong. when I echo out the posted answer and the value from the answers arrray they are correct. When you say == the answer is always correct -- does that mean even when the answer is wrong? If so, then there's something else going on here. But, I believe the answer is: if ($_REQUEST['x'] == $correct_answers[$page-1]) { This will compare the two and if they are the same will report true. You should read the manual. hth's tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
Hi Jeremy, I tried if ( strcmp( trim($SollKombination), trim($formCheck) ) ) same negativ result. For some reason both strings are not considered to be the same. They have the same length, are of the same type and have the same content. Why PHP doesn't recognize them as beeing equal I don't get it. thanks for your help so far janbro Jeremy Privett schrieb: janbro wrote: Hello List I've got the following little code: $formCheck= $_GET['formCheck']; $SollKombination = $_SESSION['zufall']; echo $SollKombinationbr$formCheck; print gettype($formCheck); echo ---; print gettype($SollKombination); if ($SollKombination == $formCheck){ echo test; } To give you some background: This code is supposed to check if a user has tried to login via my form. Which gives me the following output: ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S string---string Everything the way it's supposed to be What I don't get is, why isn't the if statement true? Shouldn't it show test as well? Where is my mistake? I run PHP 5.1.1 on Windows. On my Win PHP 5.0 this code works proper, but not here ?!? thx JanBro Hey JanBro, Try replacing the if statement you have with this: if ( strcmp( trim($SollKombination), trim($formCheck) ) ) { echo test; } --- Jeremy Privett [ http://www.jeremyprivett.com ] Founder - Lead Software Developer - Hosting Systems Administrator Omega Vortex (http://www.omegavortex.com) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
janbro wrote: Hi Jeremy, I tried if ( strcmp( trim($SollKombination), trim($formCheck) ) ) same negativ result. For some reason both strings are not considered to be the same. They have the same length, are of the same type and have the same content. Why PHP doesn't recognize them as beeing equal I don't get it. thanks for your help so far janbro This is just a shot in the dark, but have you checked the HTML source of your test to make sure that some of the characters aren't been parsed as HTML entities? That would technically make the strings different, but you wouldn't be able to tell with just echoing alone. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
I would guess that the '' in $_GET['formCheck'] will cause problems... Trying your code without the ampersand as in: $_GET['formCheck'] = 'ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S' It works just fine. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Comparing of string
Hello List I've got the following little code: $formCheck= $_GET['formCheck']; $SollKombination = $_SESSION['zufall']; echo $SollKombinationbr$formCheck; print gettype($formCheck); echo ---; print gettype($SollKombination); if ($SollKombination == $formCheck){ echo test; } To give you some background: This code is supposed to check if a user has tried to login via my form. Which gives me the following output: ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S string---string Everything the way it's supposed to be What I don't get is, why isn't the if statement true? Shouldn't it show test as well? Where is my mistake? I run PHP 5.1.1 on Windows. On my Win PHP 5.0 this code works proper, but not here ?!? thx JanBro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
Hi JanBro: Quick guess: are the strings the same length? I've been bitten many times by string comparisons that appear to be identical but which fail due to trailing spaces, other invisible (i.e., non-printing) characters, and the like. Hope this helps. Jon - Original Message - From: janbro [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, January 03, 2006 11:22 PM Subject: [PHP] Comparing of string Hello List I've got the following little code: $formCheck= $_GET['formCheck']; $SollKombination = $_SESSION['zufall']; echo $SollKombinationbr$formCheck; print gettype($formCheck); echo ---; print gettype($SollKombination); if ($SollKombination == $formCheck){ echo test; } To give you some background: This code is supposed to check if a user has tried to login via my form. Which gives me the following output: ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S string---string Everything the way it's supposed to be What I don't get is, why isn't the if statement true? Shouldn't it show test as well? Where is my mistake? I run PHP 5.1.1 on Windows. On my Win PHP 5.0 this code works proper, but not here ?!? thx JanBro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
Yep, they are of the same length. here they are: $SollKombination ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S $formCheck ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S When creating the string on the form page only visible characters were allowed. thanks but that's not it. Jon Westcot schrieb: Hi JanBro: Quick guess: are the strings the same length? I've been bitten many times by string comparisons that appear to be identical but which fail due to trailing spaces, other invisible (i.e., non-printing) characters, and the like. Hope this helps. Jon - Original Message - From: janbro [EMAIL PROTECTED] To: php-general@lists.php.net Sent: Tuesday, January 03, 2006 11:22 PM Subject: [PHP] Comparing of string Hello List I've got the following little code: $formCheck= $_GET['formCheck']; $SollKombination = $_SESSION['zufall']; echo $SollKombinationbr$formCheck; print gettype($formCheck); echo ---; print gettype($SollKombination); if ($SollKombination == $formCheck){ echo test; } To give you some background: This code is supposed to check if a user has tried to login via my form. Which gives me the following output: ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S string---string Everything the way it's supposed to be What I don't get is, why isn't the if statement true? Shouldn't it show test as well? Where is my mistake? I run PHP 5.1.1 on Windows. On my Win PHP 5.0 this code works proper, but not here ?!? thx JanBro -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Comparing of string
janbro wrote: Hello List I've got the following little code: $formCheck= $_GET['formCheck']; $SollKombination = $_SESSION['zufall']; echo $SollKombinationbr$formCheck; print gettype($formCheck); echo ---; print gettype($SollKombination); if ($SollKombination == $formCheck){ echo test; } To give you some background: This code is supposed to check if a user has tried to login via my form. Which gives me the following output: ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S ZL0X~TT4PQ%0~R0OXPRUHY7E!4~W337J71V4WDDI6$GS9480XP0TNP2I$1YX75S string---string Everything the way it's supposed to be What I don't get is, why isn't the if statement true? Shouldn't it show test as well? Where is my mistake? I run PHP 5.1.1 on Windows. On my Win PHP 5.0 this code works proper, but not here ?!? thx JanBro Hey JanBro, Try replacing the if statement you have with this: if ( strcmp( trim($SollKombination), trim($formCheck) ) ) { echo test; } --- Jeremy Privett [ http://www.jeremyprivett.com ] Founder - Lead Software Developer - Hosting Systems Administrator Omega Vortex (http://www.omegavortex.com) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php