PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm currently using a mail form to achieve a simple order form task. However, I want to be able to have an if statement to see if the payment method selected was PayPal or not and if it is to display something entirely different than if something else would have been selected.
<?
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$firstname=$_POST['name1'];
$lastname=$_POST['name2'];
$email=$_POST['email'];
$payment=$_POST['payment'];
$address=$_POST['address'];
$country=$_POST['country'];
$state=$_POST['state'];
$city=$_POST['city'];
$to="fxdesigning@gmail.com";
$message="This person has ordered a membership package:\n----------------------------------------------------------\nName: $firstname $lastname\nEmail: $email\n----------------------------------------------------------\n Desired username: $username\nPassword: $password\nConfirmed password: $password2\nPayment Method: $payment\n\nBilling Information: \nStreet Address: $street\nCountry: $country\nState: $state\nCity: $city\n ZIP Code: $zip\n ";
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n")) {
echo "Thank you, $firstname, for purchasing a membership. The administrator will need to approve and set up your account. Please be patient and you will receive an email shortly on the confirmation of your account.<br><br>If you did not fill in all of the fields correctly, your order will not be processed correctly.";
} else {
echo "Sorry $firstname but there was a problem placing the order, please check you filled out the form correctly.";
}
?>
Thank you in advance.
Last edited by sonicthehedgehog on Fri Sep 02, 2005 1:54 pm, edited 1 time in total.
<html>
<body bgcolor="#FFFFFF">
<?
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$firstname=$_POST['name1'];
$lastname=$_POST['name2'];
$email=$_POST['email'];
$payment=$_POST['payment'];
$address=$_POST['address'];
$country=$_POST['country'];
$state=$_POST['state'];
$city=$_POST['city'];
$to="fxdesigning@gmail.com";
$message="This person has ordered a membership package:\n----------------------------------------------------------\nName: $firstname $lastname\nEmail: $email\n----------------------------------------------------------\n Desired username: $username\nPassword: $password\nConfirmed password: $password2\nPayment Method: $payment\n\nBilling Information: \nStreet Address: $street\nCountry: $country\nState: $state\nCity: $city\n ZIP Code: $zip\n ";
if($payment == 'PayPal')
{
"Hi."
} else {
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n")) {
echo "Thank you, $firstname, for purchasing a membership. The administrator will need to approve and set up your account. Please be patient and you will receive an email shortly on the confirmation of your account.<br><br>If you did not fill in all of the fields correctly, your order will not be processed correctly.";
} else {
echo "Sorry $firstname but there was a problem placing the order, please check you filled out the form correctly.";
}
?>
</body>
</html>
And I received the following error:
Parse error: parse error, unexpected '}', expecting ',' or ';' in processorder.php on line 20
I also tried using echo, but nothing changed no matter what I tried using in addition.
if($payment == 'PayPal') {
"Hi.";
}
else {
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n")) {
echo "Thank you, $firstname, for purchasing a membership. The
administrator will need to approve and set up your account.
Please be patient and you will receive an email shortly on the
confirmation of your account.<br><br>If you did not fill in all
of the fields correctly, your order will not be processed correctly.";
}
else {
echo "Sorry $firstname but there was a problem placing the order, please check you filled out the form correctly.";
}
}
Ok, it works now and I also entered an html form by ending the php right after the echo and then starting it right after the form complete. I also added another if statement to send the order as an email no matter what payment was selected. Like so:
if($payment == 'PayPal')
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n"))
{
echo ?>Please complete your order by clicking "Pay."<br><br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="email@myaddress.com">
<input type="hidden" name="item_name_1" value="Membership Access">
<input type="hidden" name="amount_1" value="20.00">
<input type="submit" name="submit" value="Pay">
</form>
<?
}
else {
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n")) {
echo "Thank you, $firstname, for purchasing a membership. The
administrator will need to approve and set up your account.
Please be patient and you will receive an email shortly on the
confirmation of your account.<br><br>If you did not fill in all
of the fields correctly, your order will not be processed correctly.";
}
else {
echo "Sorry $firstname but there was a problem placing the order, please check you filled out the form correctly.";
}
}
?>
It works fine. Does anyone see any problems with it that might come up later?
Thanks so much for helping me through this. It's greatly appreciated.
Actually, now that I try it with the options of Money Order or Cashier's Check, the order isn't sent and nothing shows on the page. I know there's something simple that I'm missing that'll solve it. Ideas?
your newest code only supports PayPal. The else immediately before the second mail() is attached to the if with the first mail() call. Adding an opening brace after the PayPal check, and a closing brace before the first else should get the behaviour back. Note: you will not have an errors showing for the PayPal mail() call unless you add them.
if($payment == 'PayPal')
{
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n"))
{
?>Please complete your order by clicking "Pay."<br><br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="email@myaddress.com">
<input type="hidden" name="item_name_1" value="Membership Access">
<input type="hidden" name="amount_1" value="20.00">
<input type="submit" name="submit" value="Pay">
</form>
<?
}
} else {
if(mail($to,"$firstname $lastname has purchased a membership!",$message,"From: $email\n")) {
echo "Thank you, $firstname, for purchasing a membership. The
administrator will need to approve and set up your account.
Please be patient and you will receive an email shortly on the
confirmation of your account.<br><br>If you did not fill in all
of the fields correctly, your order will not be processed correctly.";
}
else {
echo "Sorry $firstname but there was a problem placing the order, please check you filled out the form correctly.";
}
}
?>