PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 27th, 2012, 05:40 PM
Saves Saves is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 16 Saves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 22 m 57 sec
Reputation Power: 0
Red face + Shipping Fee (QUESTION FOR PHP)

Hello PHP Community,

I have been eagerly searching the web for clues on how to implement this seemlingly easy function. I have attempted it myself many times but now I must resort to my final option, which whould be to ask you guys!

I have a very simple shopping cart I made for my website, but I can't seem to get this extra shipping fee (drop down menu) to add to the total when selected.

Here is a picture to better visualize:
http://imageshack.us/photo/my-images/811/helpmg.jpg/

If anyone knows how I can add the $15.00 to the TOTAL when selected (via drop down menu), please let me know. It would be greatly appreciated!

Reply With Quote
  #2  
Old December 27th, 2012, 11:54 PM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
we'd need to see your code to be more precise, but in a nutshell you would use javascript to modify the page (or use an ajax call) when the dropdown is changed to add or subtract the $15 from the total. I assume that there is a processing page that is called by your form, on that page you would check to see which shipping method was selected and adjust the total accordingly.
__________________
"Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

Looking for a project Idea?

Reply With Quote
  #3  
Old December 28th, 2012, 04:27 AM
Saves Saves is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 16 Saves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 22 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by sir_drinxalot
we'd need to see your code to be more precise, but in a nutshell you would use javascript to modify the page (or use an ajax call) when the dropdown is changed to add or subtract the $15 from the total. I assume that there is a processing page that is called by your form, on that page you would check to see which shipping method was selected and adjust the total accordingly.


Sure thing, here is my codes:

PHP:

PHP Code:
<?php 
session_start
();

//include "scripts/mysql.php"; 

if ((!isset($_SESSION['step'])) || ($_SESSION['step'] < 3)) {
      
header("location:x.php");
    exit(); 
}

$_SESSION['step'] = 4;

define('STEP'3);

$step '';
$step $_SESSION['step'];

$_SESSION['plan'];

if ((!isset(
$_SESSION['fullname'])) || ($_SESSION['email']) || ($_SESSION['phone'])) {

    } else {
    
$_SESSION['fullname'] = $_POST['fullname'];
    
$_SESSION['email'] = $_POST['email'];
    
$_SESSION['phone'] = $_POST['phone'];
    }
    

$pname='';
$pcost='';
$psong='';
$total='';
$nxtday="0";

        if (
$_SESSION['plan'] == 'plan1') {
            
$pname "Single";
            
$pcost "89";
            
$psong "1";
        } else if (
$_SESSION['plan'] == 'plan2') {
            
$pname "Demo";
            
$pcost "240";
            
$psong "3";
        } else if (
$_SESSION['plan'] == 'plan3') {
            
$pname "EP";
            
$pcost "415";
            
$psong "4-6";
        } else if (
$_SESSION['plan'] == 'plan4') {
            
$pname "Full";
            
$pcost "575";
            
$psong "10-15";
        } else {
            
$pname "ERROR";
            
$pcost "ERROR";
            
$psong "ERROR";
        }


$total $pcost $nxtday;

?>


HTML:

Code:
                                        
						<div style="padding-top: 120px;">
							<table width='100%' border='1' bordercolor="#eaeaea" cellspacing='0' cellpadding='6'>
							<tr>
							<td width='12%' bgcolor='#e0e0e0'><div align='center' class='cart'>Product</div></td>
							<td width='25%' bgcolor='#e0e0e0'><div align='center' class='cart'>Service Name</div></td>
							<td width='10%' bgcolor='#e0e0e0'><div align='center' class='cart'>Songs</div></td>
							<td width='10%' bgcolor='#e0e0e0'><div align='center' class='cart'>Quantity</div></td>
							<td width='10%' bgcolor='#e0e0e0'><div align='center' class='cart'>Price</div></td>
							<td width='10%' bgcolor='#e0e0e0'><div align='center' class='cart'>Change</div></td>
							<tr>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'><img src="images/white_r.png" alt="" width="51" height="52" /></div></td>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'><?php echo $pname; ?> Mastering Service</div></td>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'><?php echo $psong; ?></div></td>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'>1</div></td>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'>$<?php echo $pcost; ?></div></td>
							<td bgcolor='#e5e5e5'><div align='center' class='cart'><a href="s2.php"><img src="images/changeicon.png" alt="" width="52" height="52" /></a></div></td>
							</tr>
							</tr>
							</table>
						</div>

							<div style="float:right;margin-top: 5px;">         
								<div style="float:right;width: 720px; height:16px; background-image:url(images/total_bg.png);"><font style="float:right; margin-right: 5px;">Subtotal: $<?php echo $pcost; ?></font></div><br /></div> 
									<div style="margin-top: 10px; margin-bottom: 10px; float:right; width: 720px;"> 
										<select id="" style="float:right;" name='Delivery Speed'> 
										<option selected="selected">FREE - Standard (2-3 business days)</option> 
										<option value="nxtday" id="nxtday">$15.00 - Next Day</option> 
										</select><br />
									</div>
    
									<div style="float:right;width: 720px; height:16px; background-image:url(images/total_bg.png);"><font style="float:right; margin-right: 5px;">Total: $<?php echo $total; ?></font></div><br /></div>

Reply With Quote
  #4  
Old December 28th, 2012, 05:19 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
so in your php you have $nxtday="0";

you should be able to set that to either 0 or 15 depending on what was selected in the drop down. If that drop down changes you can use ajax to make a call back to the server to update everything and seamlessly change the html to reflect the new total.

hope that makes sense.

Reply With Quote
  #5  
Old December 28th, 2012, 06:29 AM
Saves Saves is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 16 Saves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 22 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by sir_drinxalot
so in your php you have $nxtday="0";

you should be able to set that to either 0 or 15 depending on what was selected in the drop down. If that drop down changes you can use ajax to make a call back to the server to update everything and seamlessly change the html to reflect the new total.

hope that makes sense.


Is there a way to do it with PHP? Because I do not know of Java.

Reply With Quote
  #6  
Old December 28th, 2012, 05:33 PM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
yes, very easily. From the look of the image you provided in your first post, paypal is the next step. You might be able to get paypal to handle it (i don't know enough about paypal to say for certain).

The other way would be to add an extra step in, so that users select their shipping service, the click a 'next' button which will send the value of the drop down to the php script, then you can access it as part of the $_POST[] array. I can't see any <form> tag in your html either, so if it is not in there, you will need to add something like <form action="myscriptname.php" method="post"> so that the browser knows what to do with the data.

Reply With Quote
  #7  
Old December 31st, 2012, 03:17 AM
Saves Saves is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 16 Saves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 22 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by sir_drinxalot
yes, very easily. From the look of the image you provided in your first post, paypal is the next step. You might be able to get paypal to handle it (i don't know enough about paypal to say for certain).

The other way would be to add an extra step in, so that users select their shipping service, the click a 'next' button which will send the value of the drop down to the php script, then you can access it as part of the $_POST[] array. I can't see any <form> tag in your html either, so if it is not in there, you will need to add something like <form action="myscriptname.php" method="post"> so that the browser knows what to do with the data.


Ok, I am having a bit of trouble here... Here is my code in short form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="POST">
<select id="delivery_speed" style="float:right;" name='delivery_speed'>
<option selected="selected">FREE - Standard (2-3 business days)</option>
<option>$15.00 - Next Day</option>
</select>
</form>


I'd imagine that if the options we're values themselves, it would be much easier to do. For example, <option>15</option>
And then just add the $POST_['delivery_speed'] to subtotal to get the total. However, Since the option is the words "$15.00 - Next Day" I can't add that as a value. Instead, I would need to some how attach a value to that option. My logic does not seem to be working in my favor.

Here is what I am thinking...

<select id="delivery_speed" name='delivery_speed'>
<option value="free">FREE - Standard (2-3 business days)</option>
<option value="nxtday">$15.00 - Next Day</option>
</select>


and have this in php...

$free = "0";
$nxtday = "15";


Then have this...

$delivery_speed = $_POST['delivery_speed'];
$total = $sub + $delivery_speed;


But this will not work.... All I want to happen is for when the user selects the "$15.00 - Next Day" in the drop down menu. That it would automatically calculate and add $15 to the total, and if the user selects "FREE - Standard (2-3 business days)" it would add $0 to the total...

Reply With Quote
  #8  
Old December 31st, 2012, 06:14 AM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
Close... you would keep the html as you have it:

Code:
<select id="delivery_speed" name='delivery_speed'> 
<option value="free">FREE - Standard (2-3 business days)</option>
<option value="nxtday">$15.00 - Next Day</option>
</select>


and then this in the php

PHP Code:
if($_POST['delivery_speed'] == "free") {
$total $sub;
} else {
$total $sub 15;



or

PHP Code:
if($_POST['delivery_speed'] == "free") {
$postage 0;
} else {
$postage 15;
}
$total $sub $postage


something like that should do what you want.

Reply With Quote
  #9  
Old December 31st, 2012, 06:55 AM
Saves Saves is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 16 Saves User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 22 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by sir_drinxalot
Close... you would keep the html as you have it:

Code:
<select id="delivery_speed" name='delivery_speed'> 
<option value="free">FREE - Standard (2-3 business days)</option>
<option value="nxtday">$15.00 - Next Day</option>
</select>


and then this in the php

PHP Code:
if($_POST['delivery_speed'] == "free") {
$total $sub;
} else {
$total $sub 15;



or

PHP Code:
if($_POST['delivery_speed'] == "free") {
$postage 0;
} else {
$postage 15;
}
$total $sub $postage


something like that should do what you want.


For some reason, the total keeps echoing out 15 no matter what option i select. I also tried both of your codes. I don't understand why it won't simply add the subtotal with 15?... The subtotal is echoing out just fine though. Here's a pic..
http://i78.photobucket.com/albums/j89/Savesx/image_zps06dbed4f.png

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > + Shipping Fee (QUESTION FOR PHP)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap