954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

if else statement with $_POST

can i check is there anything wrong with my if else, if seems like it will only go banktransfer.php instead.

if ($_POST[Payment] = "Bank Transfer") {
	$btpage = "banktransfer.php";
		
		echo '<script language="javascript" type="text/javascript">window.location.href="'.$btpage.'";</script>';
		}
		else if ($_POST[Payment] = "Credit Card") {
			$ccpage = "creditcard.php";
		
		echo '<script language="javascript" type="text/javascript">window.location.href="'.$ccpage.'";</script>';
}

		else   {
			$pppage = "paypal.php";
		
		echo '<script language="javascript" type="text/javascript">window.location.href="'.$pppage.'";</script>';
}
issaru07
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

You're using = instead of ==

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 
You're using = instead of ==

thanks. i tried using == , and all options will redirect to paypal.php instead

issaru07
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

arrays are quoted if ($_POST['Payment']


many servers in the path between your server and the client do not handle spaces well, the $_post-ed value would be better as Bank_Transfer

javascript redirects when using a server language ??
why send anything but the correct page to the client

<?php 
if($_POST['Payment'] == 'Bank_Transfer') {header("Location: banktransfer.php");
elseif($_POST['Payment'] == 'Credit_Card') {header("Location: creditcard.php");
else {header("Location: paypal.php");


or switch / case

edited '==' :(

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

Still single equals :)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

arrays are quoted if ($_POST['Payment']

many servers in the path between your server and the client do not handle spaces well, the $_post-ed value would be better as Bank_Transfer

javascript redirects when using a server language ?? why send anything but the correct page to the client

<?php 
if($_POST['Payment'] == 'Bank_Transfer') {header("Location: banktransfer.php");
elseif($_POST['Payment'] == 'Credit_Card') {header("Location: creditcard.php");
else {header("Location: paypal.php");

or switch / case

edited '==' :(

still the same. i tried using credit_card and bank_transfer instead. all pointing to paypal.php

below is part of the form page

Payment Type:
  
<SELECT NAME="payment">
<OPTION VALUE="">Choose a Payment Type

<OPTION VALUE="Bank_Transfer">Bank Transfer</option>

<OPTION VALUE="Paypal">Paypal</option>

<OPTION VALUE="Credit_Card">Credit Card</option>





</SELECT>
issaru07
Light Poster
40 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

in the form <select name='payment'

in the handler if($_POST['Payment']

Case sensitive?? maybe; payment ≠ Payment ;
$_POST['Payment'] == "";//none of the checks return true, default 'else' result Paypal

change either the html form or the php handler, so they both use the same name

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You