Current location: Hot Scripts Forums » Programming Languages » PHP » Is This Possible With PHP?


Is This Possible With PHP?

Reply
  #1 (permalink)  
Old 04-09-06, 10:52 AM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Question Is This Possible With PHP?

Hello, I'm trying to make a shipping rate calucuator.

Basicly I want the person to choose a shipping company, and then have it excute a specific code (shipping rates).

Can someone tell me why this code isn't working, or a better method of doing this.

Thanks Keith,

PHP Code:

// START // Globals

$weight $_POST['weight'];
$shipping_company $_POST['shipping_company'];
// END // Globals

switch($_GET['shipping_company']){
case 
'usps':
$rate ".99"// Rate Per OZ
$shippingcost $weight $rate;
echo(
"$shippingcost");
break;
case 
'ups':
$rate ".99"// Rate Per OZ
$shippingcost $weight $rate;
echo(
"$shippingcost");
break;
case 
'fedex':
$rate ".99"// Rate Per OZ
$shippingcost $weight $rate;
echo(
"$shippingcost");
break;
default:
echo(
"Some Page"); 
break;

Code:
<div  align=center>
<form action=shipping_rates.php method=POST>
<select name=shipping_company>
<option>USPS</option>
<option>UPS</option>
<option>Fedex</option>
</select>
<input type=text name="weight" />Enter OZ Only<br />
<input type=submit>
</form>
</div>

Last edited by Christian; 04-09-06 at 04:10 PM. Reason: Fixed vB code....
Reply With Quote
  #2 (permalink)  
Old 04-09-06, 10:57 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Havent checked for sure, but the "weight" in the default echo should be \"

Ill check the full code out now.
Reply With Quote
  #3 (permalink)  
Old 04-09-06, 11:08 AM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
i corrected the code, I should of said it was 2 diffrent files. one submites to the other for handling.
Reply With Quote
  #4 (permalink)  
Old 04-09-06, 11:31 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
I'm just redoing the file for you now. Its okay to have it on the same page.
Reply With Quote
  #5 (permalink)  
Old 04-09-06, 11:34 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
The most obvious reason for this not working is you are using the POST method in your form, but you are attempting to use $_GET[...] to access the data. This is likely returning a null value and not really doing anything.

PHP Code:

$shipping_company $_POST['shipping_company']; 

// END // Globals 

switch($_GET['shipping_company']) 
You are also setting the $shipping_company variable correctly, but not using it, instead you are using the $_GET in the switch statement.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #6 (permalink)  
Old 04-09-06, 11:39 AM
coolmark18's Avatar
coolmark18 coolmark18 is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<?php


$_POST
['shippingcompany'] = $shippingcompany;
$_POST['weight'] = $weight;


switch (
$shippingcompany){
    case 
"usps":
        
$rate 0.69;
        
$cost $rate*$weight;
        echo 
"Shipping Cost will equal to ".$cost;
        break;
     case 
"ups":
        
$rate 0.99;
        
$cost $rate*$weight;
        echo 
"Shipping Cost will equal to ".$cost;
         break;
     case 
"fedex":
        
$rate 0.99;
        
$cost $rate*$weight;
        echo 
"Shipping Cost will equal to ".$cost;
         break;
     default:
         echo 
"

<form action=\"\" method=\"post\">
  Shipping Company:
  <select name=\"shippingcompany\" id=\"shippingcompany\">
    <option value=\"ups\">UPS</option>
    <option value=\"usps\">USPS</option>
    <option value=\"fedex\">Fedex Delivery</option>
  </select>
  <br>
  Weight: 
  <input name=\"weight\" type=\"text\" id=\"weight\">
  <br>
  <input type=\"submit\" name=\"Submit\" value=\"Submit\">
</form>

"
;
         break;
}

?>
I believe thats working fine If not give me a shout.
Reply With Quote
  #7 (permalink)  
Old 04-09-06, 11:48 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
If you are building a real cart that will handle shipping, you might want to consider using a commercial cart like x-cart.com. They have realtime shipping interfaces for USPS, UPS, and FedEx.
Reply With Quote
  #8 (permalink)  
Old 04-09-06, 02:52 PM
KeYBLeR KeYBLeR is offline
Newbie Coder
 
Join Date: Jan 2006
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Mab and coolmark, I have figured that out.

Keith
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 08:26 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
PHP / Graphic Developers someotherguy582 Job Offers & Assistance 1 06-05-05 07:40 PM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM


All times are GMT -5. The time now is 07:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.