Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
If/Else Statements in Email
Old 04-21-2005, 11:58 PM If/Else Statements in Email
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Trades: 0
I've been working on a signup form for my free hosting... And in this form (which can be found here ) I use an if/else statement to where if a user wants a new email address at my site it prints "$new_emailadd@dreammare.net", or if they don't want a new email address, it prints "none." Now, all 5 pages of my signup form work (as far as I know), however, in create.php (the page that emails the request to me and a copy to the new user) that if/else statement doesn't seem to work. Here is how I have the statement setup on my other pages:

Code:
<u>Account Extras</u> (Optional)<p></td> <tr><td>
New Email Address:</td><td align="left">
<?php
$new_email = $_POST['new_email'];
$newemail = $_POST['newemail'];

if ( $new_email == yes ) {
echo "$newemail@dreammare.net";
} else {
echo "none";
}

?>

The thing is, that is PHP inside of HTML... The part of my create.php page that needs the if/else statement is entirely PHP. I'm sure this is totally wrong, but this is how I have it now (at the top of the page):


Code:
<?php
$newemail = $newemail;
$new_email = $_POST['new_email'];
$new_emailadd = $_POST['new_emailadd'];

if ( $new_email == yes ) {
$newemail = "$newemail_add@dreammare.net";
} else {
$newemail = "none";
}
?>
Keep in mind... I started coding a year and a half, then stopped for "maternity leave." My memory's a bit cloudy on the proper way to code if/else and no tutorials seemed to help any. Anywhos, this is the part of the script that calls for the result of the if/else:


Code:
<?
$UserMessage = "Thanks for your request, $username.\n\n";
$UserMessage .= "An account with the following details will be created ASAP:\n\n";
$UserMessage .= "Username: $username.dreammare.net\n";
$UserMessage .= "Password: $pw1\n";
$UserMessage .= "New Email: $newemail\n";
$UserMessage .= "Install These Scripts: $sel_scripts\n\n";
$UserMessage .= "Additional Comments:\n";
$UserMessage .= "$comments\n\n";
$UserMessage .= "If you have any further questions, please email me at:\n";
$UserMessage .= "$SiteEmail\n\n";
$UserMessage .= "-$SiteUserName\n\n";
mail("$cur_email", "$ThankYou", $UserMessage, "From: $SiteEmail");
$AdminMessage = "$username Submitted the following Information:\n\n";
$AdminMessage .= "Username: $username.dreammare.net\n";
$AdminMessage .= "Password: $pw1\n";
$AdminMessage .= "New Email: $newemail\n";
$AdminMessage .= "Install These Scripts: $sel_scripts\n\n";
$AdminMessage .= "Additional Comments:\n";
$AdminMessage .= "$comments\n\n";
mail("$SiteEmail", "$SiteName - Account Request", $AdminMessage, "From: $cur_email");
?>

In the emails that are sent, the "New Email:" just comes out as "@dreammare.net"
I'm trying to figure out how to pass the "$new_emailadd" or "none" variables into the sent email. Any ideas? I'd greatly appreciate it! (And after that, I have an issue with keeping data stored in a text box while using the back/forward buttons :/)
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
 
Register now for full access!
Old 04-22-2005, 01:06 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
I am assuming that the value held in $_POST['new_email'] is a string. In fact, I'm sure of it. So when you do your check, be sure to represent the word yes as a string:

PHP Code:
if ( $new_email == "yes" 
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 04-22-2005, 05:20 PM
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Trades: 0
I'm sorry, but could you elaborate for me, please?
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 04-22-2005, 05:29 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by SunBlind
I'm sorry, but could you elaborate for me, please?
Anything coming out of the $_POST superglobal array is a string. When performing your check (look at your if statement), the word yes is not enclosed in single or double quotes -- PHP has no idea what to do with just yes whereas "yes" is a string.

You must represent a literal string in quotes (either single or double).
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 04-22-2005, 07:09 PM
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Trades: 0
Oooh.... gotcha! Well it works for the other pages that are using the statement... As I learned from my other posts, I may be going about the question all wrong. If I can't create a new variable from the if/else statement, then how can I implement the statement into the mail code where it is supposed to print the user's new email address or "none?" Like this:

Code:
<?
$UserMessage = "Thanks for your request, $username.\n\n";
$UserMessage .= "An account with the following details will be created ASAP:\n\n";
$UserMessage .= "Username: $username.dreammare.net\n";
$UserMessage .= "Password: $pw1\n";
$UserMessage .= "New Email: <-- if/else here somehow-->\n";
$UserMessage .= "Install These Scripts: $sel_scripts\n\n";
$UserMessage .= "Additional Comments:\n";
$UserMessage .= "$comments\n\n";
$UserMessage .= "If you have any further questions, please email me at:\n";
$UserMessage .= "$SiteEmail\n\n";
$UserMessage .= "-$SiteUserName\n\n";
mail("$cur_email", "$ThankYou", $UserMessage, "From: $SiteEmail");
$AdminMessage = "$username Submitted the following Information:\n\n";
$AdminMessage .= "Username: $username.dreammare.net\n";
$AdminMessage .= "Password: $pw1\n";
$AdminMessage .= "New Email: <-- if/else here somehow-->\n";
$AdminMessage .= "Install These Scripts: $sel_scripts\n\n";
$AdminMessage .= "Additional Comments:\n";
$AdminMessage .= "$comments\n\n";
mail("$SiteEmail", "$SiteName - Account Request", $AdminMessage, "From: $cur_email");
?>
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 04-23-2005, 12:54 AM
Logical Program's Avatar
Super Talker

Posts: 130
Location: Atlanta, Georgia
Trades: 0
Just quote the word "yes" in your if statement. Without quotes, your if statement is assuming a boolean state of being of some sort.
__________________

Please login or register to view this content. Registration is FREE
- For all of your website programming and design needs, make the logical choice. Logical Assistance For Real-World Clients.
Logical Program is offline
Reply With Quote
View Public Profile Visit Logical Program's homepage!
 
Old 04-23-2005, 04:52 AM
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Trades: 0
Still no luck... just a blank spot where the new email address should be. Let me ask a few more specific questions:

1. Is it even possible to create a new variable from an if/else statement?
2. Can an if/else be inserted into the code (refer to my last post) without causing a line break?
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Old 04-23-2005, 10:15 AM
Experienced Talker

Posts: 32
Name: Rae
Location: Severn, MD USA
Trades: 0
Problem solved!!! I stumbled upon a page giving reference to something called a ternary operator... And it was exactly what I needed! So instead of that ugly old if/else statement I am now using
Code:
$newemail = ($new_email == yes) ? $new_emailadd . '@dreammare.net' : 'none';
now everything works great! Check it out
SunBlind is offline
Reply With Quote
View Public Profile Visit SunBlind's homepage!
 
Reply     « Reply to If/Else Statements in Email
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.12044 seconds with 12 queries