switch

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!

Moderator: General Moderators

Post Reply
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

switch

Post by radium35 »

what am i doing wrong here? the script echo's all includes at the same time? :banghead:


$a1=$_POST[first_name];
$a2=$_POST[last_name];
$a3=$_POST[work_phone];
$a4=$_POST[cell_phone];
$a5=$_POST[company];
$a6=$_POST[address];
$a7=$_POST[address_2];
$a8=$_POST[city];
$a9=$_POST[state];
$a10=$_POST[zip];
$a11=$_POST[email];
$a12=$_POST[sem_id];
$a13=$_POST[sem_title];
$a14=$_POST[sem_month];
$a15=$_POST[sem_day];
$a16=$_POST[sem_year];
$a17=$_POST[sem_time_hr];
$a18=$_POST[sem_time_min];
$a19=$_POST[sem_time_day];
$a20=$_POST[payment_type];


$paypalbutton = (include 'sem_paypalbutton.php');
$ccpayment = (include 'sem_ccpayment.php');
$checkpayment = (include 'sem_checkpayment.php');

switch ($a20) {
case "Pay Pal":
echo "$paypalbutton";
break;
case "Credit Card":
echo "$ccpayment";
break;
case "Check":
echo "$checkpayment";
break;
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: switch

Post by requinix »

Don't do the include until you need it.

Code: Select all

switch ($a20) {
case "Pay Pal":
include 'sem_paypalbutton.php'
break;
case "Credit Card":
include 'sem_ccpayment.php'
break;
case "Check":
include 'sem_checkpayment.php'
break;
}
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: switch

Post by Mark Baker »

Are there any echo or print statements inside your included files?

I'm assuming that it does have a return
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: switch

Post by radium35 »

tasairis wrote:Don't do the include until you need it.

Code: Select all

switch ($a20) {
case "Pay Pal":
include 'sem_paypalbutton.php'
break;
case "Credit Card":
include 'sem_ccpayment.php'
break;
case "Check":
include 'sem_checkpayment.php'
break;
}

This worked perfect 8) thanks "tasairis"! glad it works don't understand why i can echo a variable with an include??
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: switch

Post by radium35 »

Mark Baker wrote:Are there any echo or print statements inside your included files?

I'm assuming that it does have a return
ne, the include file has the payment information
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: switch

Post by requinix »

radium35 wrote:This worked perfect 8) thanks "tasairis"! glad it works don't understand why i can echo a variable with an include??
include isn't a function. It doesn't evaluate the file and return what it tried to print.
It just evaluates it.

You can do a couple other things if you know what you're doing, but it seems you weren't doing them.
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: switch

Post by radium35 »

tasairis wrote:
radium35 wrote:This worked perfect 8) thanks "tasairis"! glad it works don't understand why i can echo a variable with an include??
include isn't a function. It doesn't evaluate the file and return what it tried to print.
It just evaluates it.

You can do a couple other things if you know what you're doing, but it seems you weren't doing them.

umm... ok :crazy:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: switch

Post by requinix »

radium35 wrote:
tasairis wrote:
radium35 wrote:This worked perfect 8) thanks "tasairis"! glad it works don't understand why i can echo a variable with an include??
include isn't a function. It doesn't evaluate the file and return what it tried to print.
It just evaluates it.

You can do a couple other things if you know what you're doing, but it seems you weren't doing them.

umm... ok :crazy:
Ever tried to do this?

Code: Select all

function test() {
    echo "three";
}
 
$three = test();
echo "one plus two is " . $three;
It doesn't work the way you want for the exact same reason.
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: switch

Post by radium35 »

ok, i get it. That makes sense now. :D
Post Reply