Web Hosting Talk







View Full Version : $em2 == $em1 IF $em2 == "" in php - suggestions?


Mark Raven
08-29-2004, 12:59 PM
EDIT: I seem to have fixed this. No idea what was wrong, but I no longer need help.

Basically, I have two fields that are entered through a form:

$email1 (the email which they used to pay me through paypal)
$email2 (the email which they want me to use when contacting them)

$email1 is required. $email2 is only required if the email they want me to contact them with is different from their paypal email address. Once they click "submit", I want to send a "thank you for ordering" message... to the email they want me to contact them at. This means I need to use what they entered in $email2 UNLESS they left it blank, in which case I'd need to use what they entered in $email1.

I thought something simple like this would work:


if ($email2 == "")
{
$mailto = $email1;
} else {
$mailto = $email2;
}


But apparently, it does not send anything unless the user fills in both $email1 and $email2 themselves.

Any idea what's wrong, or how I could fix it?

RackNine
08-29-2004, 01:11 PM
Mark,

Your if statement seems to work from my home PC (PHP 4.3.8). I ran an extract($_POST) to obtain the variable names on two text entries.

Try this instead:

$mailto = ($email2 == "") ? $email1 : $email2;

It's an embedded IF statement with the same result as your code. If problems persist take a look at your form or means of extracting variables as something might be wrong there.

-Matt

Mark Raven
08-29-2004, 01:27 PM
Thanks for the suggestion. I seem to have got it fixed, but I'm going to consider using your method.