html form and php

Reply

Join Date: Jan 2009
Posts: 123
Reputation: shasha821110 is an unknown quantity at this point 
Solved Threads: 2
shasha821110 shasha821110 is offline Offline
Junior Poster

html form and php

 
0
  #1
Mar 8th, 2009
Hi, all.
Really new on php!!
I want to implement one function which could get the price depending on different size and calculate the total price.

So i made foo.php and bar.php. Which people could choose the size and the price in foo.php and want to pass which they choose to the bar.php. Got stuck there.

Here is my foo.php form code:
  1. <form name="choosesize" method="get" action="bar.php">
  2. <p>Choose Size / Price</p>
  3. //$sizeLp is the item's Large size price
  4. <input type="radio" name="sizeL" value="<?php echo $sizeLp; ?>">Price(L):&nbsp;<?php print($sizeLp);?></input><br/>
  5. //$sizeSp is the item's small size price
  6. <input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S):&nbsp;<?php print($sizeSp);?></input><br/><br/>
  7. <input type="submit" value="Submit"></input>
  8. </form>

Here is my bar.php code:
  1. if(isset($_GET["size"]) && !empty($_GET["size"]))
  2. {
  3. switch ($_GET["size"])//"size is the radio button name"
  4. {
  5. case "sizeL"://sizeL is the first input button name
  6. $price=$_GET["value"];//want to get the first button value
  7. break;
  8. case "sizeS"://sizeS is the second input button name
  9. $price=$_GET["value"];//want to get the second button value
  10. break;
  11.  
  12. }
  13. }

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 796
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

Re: html form and php

 
0
  #2
Mar 8th, 2009
You can pass variables to the $_GET array in the action part of your form tag by changing the url to "bar.php?size=....". This will pass the parameter size to the $_GET array, accessed in your php code by $_GET["size"] . In a PHP url, anything after the .php? are variables for the $_GET array, separated by the ampersand (&) character. So a url that looks like this:
foo.php?size=1&name=Mike&goal=study&command=download
loads the page foo.bar with the $_GET having the following variables:
  1. $_GET['size'] = 1;
  2. $_GET['name'] = 'Mike';
  3. $_GET['goal'] = 'study';
  4. $_GET['command'] = 'download';

I should point out that while there is no limit to what you can pass to the $_GET array, it is visible in the browser url, so should never be used to pass sensitive information such as passwords to the browser.

I will leave it up to you to figure out what size should be set to based on what radio button is selected. A google search should be able to point you in the right direction.

HTH,
d
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 22
Reputation: Monalisaparker is an unknown quantity at this point 
Solved Threads: 0
Monalisaparker Monalisaparker is offline Offline
Newbie Poster

Re: html form and php

 
0
  #3
Mar 9th, 2009
Originally Posted by shasha821110 View Post
Hi, all.
Really new on php!!
I want to implement one function which could get the price depending on different size and calculate the total price.

So i made foo.php and bar.php. Which people could choose the size and the price in foo.php and want to pass which they choose to the bar.php. Got stuck there.

Here is my foo.php form code:
  1. <form name="choosesize" method="get" action="bar.php">
  2. <p>Choose Size / Price</p>
  3. //$sizeLp is the item's Large size price
  4. <input type="radio" name="sizeL" value="<?php echo $sizeLp; ?>">Price(L):&nbsp;<?php print($sizeLp);?></input><br/>
  5. //$sizeSp is the item's small size price
  6. <input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S):&nbsp;<?php print($sizeSp);?></input><br/><br/>
  7. <input type="submit" value="Submit"></input>
  8. </form>

Here is my bar.php code:
  1. if(isset($_GET["size"]) && !empty($_GET["size"]))
  2. {
  3. switch ($_GET["size"])//"size is the radio button name"
  4. {
  5. case "sizeL"://sizeL is the first input button name
  6. $price=$_GET["value"];//want to get the first button value
  7. break;
  8. case "sizeS"://sizeS is the second input button name
  9. $price=$_GET["value"];//want to get the second button value
  10. break;
  11.  
  12. }
  13. }

Thanks.

Whats the problem in it, ok let me try it on my PC might be possible that i will be able to find the bug
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC