943,923 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 437
  • PHP RSS
Mar 8th, 2009
0

html form and php

Expand 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:
php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster
shasha821110 is offline Offline
123 posts
since Jan 2009
Mar 8th, 2009
0

Re: html form and php

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:
php Syntax (Toggle Plain Text)
  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
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Mar 9th, 2009
0

Re: html form and php

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:
php Syntax (Toggle Plain Text)
  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:
php Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Monalisaparker is offline Offline
22 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP/HTML Question. How to change frame after login?
Next Thread in PHP Forum Timeline: Help with chat script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC