 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
02-14-2008, 03:39 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 28
Thanks: 9
|
If, else and ==
Hi, im pretty new to php, ive got some code see below from a contact form, but i need to match the email and confirm email fields, how can i do that.
php Code:
if(isValidForm ($strTempName, $strTempTelephone, $strTempMobile, $strTempEmail, $strTempConfirmEmail, $strTempCity)){ //Mail the form. //Call MaiForm Function. MailForm ($strTempName, $strTempAddress, $strTempPostcode, $strTempTelephone, $strTempMobile, $strTempEmail, $strTempConfirmEmail, $strTempCity, $strTempCelebration, $strTempStartDate, $strTempGroupSize, $strTempEnquiry, $strTempBrochure, $strTempHeardAbout) ; //Write out a thank you. //WriteMessage($strTempName, $strTempAddress, $strTempPostcode, $strTempTelephone, $strTempMobile, $strTempEmail, $strTempCity, $strTempCelebration, $strTempStartDate, $strTempGroupSize, $strTempEnquiry, $strTempBrochure, $strTempHeardAbout) ; echo "Thank you for your enquiry, a member of our reservation team will get back to you within 24 hours."; }else{ //Send an Error. echo "<div align=center" ; echo "It appears that you have left out one of the fields.<br>" ; echo "Please go back and fill in these missing fields.<br><br>" ; //Display the error. echo $strError ; }
There is more to the code but i think that is all of the relevant code.
Thanks in advance
Last edited by Wildhoney : 02-14-2008 at 04:42 PM.
|
|
|
|
02-14-2008, 03:44 PM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Inside the isValidForm function you just need to compare the two values. To check for equality just do: if ($strTempEmail == $strTempConfirmEmail) ...
|
|
|
|
|
The Following User Says Thank You to Salathe For This Useful Post:
|
|
02-14-2008, 04:02 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 28
Thanks: 9
|
ithought that was the case but im still having trouble, im getting this error now
Quote:
|
Parse error: syntax error, unexpected T_IS_EQUAL, expecting ')' in /home/sites/planetredevents.co.uk/public_html/demo/process.php on line 93
|
this is line 93 and its function;
php Code:
function isValidForm ($strTempName, $strTempTelephone, $strTempMobile, $strTempEmail, $strTempConfirmEmail, $strTempCity, $strTempEmail == $strTempConfirmEmail){ //Set strError Variable to global so we can use the Variable //outside of the function. global $strError ; //Initiate the variable by setting it eqaul to nothing. $strError = "" ; if($strTempName == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Name field.<br>" ; } if($strTempTelephone == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Telephone field.<br>" ; } if($strTempMobile == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Mobile field.<br>" ; } if($strTempEmail == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Email field.<br>" ; } if($strTempConfirmEmail == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Confirm Email field.<br>" ; } if($strTempCity == "") { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Chosen City field.<br>" ; } if($strTempEmail != $strTempConfirmEmail) { //Build the string error message by Cocantenating the strError Variable //to itself. $strError .= "Email does not match.<br>" ; } //Test to see if the strError Variable contains a message //If it does then return false (not an valid form). //If strError Variable is empty or "" then return true (is a valid form). if($strError != "") { return false ; } else { return true ; }}
Last edited by Wildhoney : 02-14-2008 at 04:42 PM.
|
|
|
|
02-14-2008, 04:14 PM
|
#4 (permalink)
|
|
The Addict
Join Date: Nov 2007
Posts: 282
Thanks: 61
|
Read below not thinking straight
----
Reason is, you can't compare variables inside function arguments.
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Last edited by Nor : 02-14-2008 at 04:50 PM.
Reason: thx sketch for clearning it up typing to fast will get to me.
|
|
|
|
02-14-2008, 04:27 PM
|
#5 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
you cant have comparisons in the functions args, i believe salathe meant inside your function definition like so:
PHP Code:
function isValidForm($strTempName, $strTempTelephone, $strTempMobile, $strTempEmail, $strTempConfirmEmail, $strTempCity, $strTempEmail, $strTempConfirmEmail) { if($strTempEmail == $strTempConfirmEmail) { //etc } }
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
Last edited by sketchMedia : 02-14-2008 at 04:35 PM.
Reason: fingers are not connected to my brain atm :(
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
02-14-2008, 05:21 PM
|
#6 (permalink)
|
|
The Contributor
Join Date: Jan 2008
Posts: 28
Thanks: 9
|
cheers guys, sorry for being a fool.
Ive got it now, was trying to rush it and not thinking about it
|
|
|
|
02-15-2008, 12:25 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
hehe np m8, all part of the learning process
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
02-15-2008, 02:13 PM
|
#8 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
You might want to use empty() to check if a string is empty, it will consider 0 as empty though.
Else its looking good ;)
|
|
|
02-15-2008, 02:21 PM
|
#9 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
Quote:
Originally Posted by Kalle
You might want to use empty() to check if a string is empty, it will consider 0 as empty though.
Else its looking good ;)
|
Why use a tremendous slow function (if used too much) if you can use if ($var == '') { continue; }.
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
02-15-2008, 07:26 PM
|
#10 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
Quote:
Originally Posted by ReSpawN
Why use a tremendous slow function (if used too much) if you can use if ($var == '') { continue; }.
|
Because empty doesn't check only if the argument is 0 (zero), it checks for other empty values, as well. This would be the rewriting of the empty function:
php Code:
function custom_empty ( $val ){ if( $val === '' || $val === 0 || $val === '0' || $val === null || $val === false || $val === array() ) { return true; } return false; }
So...why is it a so 'tremendous slow function'?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
Last edited by Wildhoney : 02-15-2008 at 08:20 PM.
|
|
|
|
02-15-2008, 07:58 PM
|
#11 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
Quote:
Originally Posted by xenon
Because empty doesn't check only if the argument is 0 (zero), it checks for other empty values, as well. This would be the rewriting of the empty function:
Code:
function custom_empty( $val )
{
if( $val === '' ||
$val === 0 ||
$val === '0' ||
$val === null ||
$val === false ||
$val === array() )
{
return true;
}
return false;
}
So...why is it a so 'tremendous slow function'?
|
I did not mean the == (why 3?) operator was slow, I meant empty() was slow. And next to that, like you said, it doesn't check all sorts of vars and arrays. You can check if the var contains something but it won't work on an array.
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
02-15-2008, 10:14 PM
|
#12 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Who says that empty() is slow and on what grounds? Also, empty does check all sorts of vars and arrays which basic comparison will not do. In the end it's about knowing what method to use for what circumstances.
P.S. The three equals symbols makes sure that the values are IDENTICAL. In other words, the comparison evaluates to TRUE if the left side is equal to the right, and they are both of the same type (string, integer, etc). For example:
PHP Code:
if (0 == 0.00) {
echo '0 is equal to 0.00';
} else {
echo '0 is not equal to 0.00';
}
if (0 === 0.00) {
echo 'and 0 is identical to 0.00';
} else {
echo 'but 0 is not identical to 0.00';
}
|
|
|
|
|
The Following User Says Thank You to Salathe For This Useful Post:
|
|
02-15-2008, 11:01 PM
|
#13 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
Thanks Salathe, yet again you proved me wrong. I heard about the empty() function being slow but you've proven me right, since I sincerely thought the other guy was right.
About the double and triply =, thanks for that. I didn't know that either. Learning a lot. 
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
02-16-2008, 03:04 PM
|
#14 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
Something that I find handy - BlueShoes: PHP Cheat Sheet - a little cheat sheet that helps you figure out what will match what when writing comparisons
Alan
|
|
|
|
The Following User Says Thank You to Alan @ CIT For This Useful Post:
|
|
02-16-2008, 03:39 PM
|
#15 (permalink)
|
|
The Frequenter
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
|
Thanks Alan, that's awesome. Seriously.
__________________
"Life is a bitch, take that bitch on a ride"
|
|
|
02-18-2008, 02:11 PM
|
#16 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Quote:
Originally Posted by ReSpawN
Thanks Salathe, yet again you proved me wrong. I heard about the empty() function being slow but you've proven me right, since I sincerely thought the other guy was right.
About the double and triply =, thanks for that. I didn't know that either. Learning a lot. 
|
To quick learn you one more thing about empty, its a language construct and not a function, meaning it cannot be called though variable functions if you are know that term =)
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|