| | |
html form and php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 123
Reputation:
Solved Threads: 2
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:
Here is my bar.php code:
Thanks.
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)
<form name="choosesize" method="get" action="bar.php"> <p>Choose Size / Price</p> //$sizeLp is the item's Large size price <input type="radio" name="sizeL" value="<?php echo $sizeLp; ?>">Price(L): <?php print($sizeLp);?></input><br/> //$sizeSp is the item's small size price <input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S): <?php print($sizeSp);?></input><br/><br/> <input type="submit" value="Submit"></input> </form>
Here is my bar.php code:
php Syntax (Toggle Plain Text)
if(isset($_GET["size"]) && !empty($_GET["size"])) { switch ($_GET["size"])//"size is the radio button name" { case "sizeL"://sizeL is the first input button name $price=$_GET["value"];//want to get the first button value break; case "sizeS"://sizeS is the second input button name $price=$_GET["value"];//want to get the second button value break; } }
Thanks.
You can pass variables to the
foo.php?size=1&name=Mike&goal=study&command=download
loads the page foo.bar with the
I should point out that while there is no limit to what you can pass to the
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
$_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)
$_GET['size'] = 1; $_GET['name'] = 'Mike'; $_GET['goal'] = 'study'; $_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. •
•
Join Date: Jan 2009
Posts: 22
Reputation:
Solved Threads: 0
•
•
•
•
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)
<form name="choosesize" method="get" action="bar.php"> <p>Choose Size / Price</p> //$sizeLp is the item's Large size price <input type="radio" name="sizeL" value="<?php echo $sizeLp; ?>">Price(L): <?php print($sizeLp);?></input><br/> //$sizeSp is the item's small size price <input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S): <?php print($sizeSp);?></input><br/><br/> <input type="submit" value="Submit"></input> </form>
Here is my bar.php code:
php Syntax (Toggle Plain Text)
if(isset($_GET["size"]) && !empty($_GET["size"])) { switch ($_GET["size"])//"size is the radio button name" { case "sizeL"://sizeL is the first input button name $price=$_GET["value"];//want to get the first button value break; case "sizeS"://sizeS is the second input button name $price=$_GET["value"];//want to get the second button value break; } }
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
![]() |
Similar Threads
- Setting up a form in PHP (PHP)
- php drop down menu to search multiple sql tables (PHP)
- Sending HTML email via PHP mail function (PHP)
- http form -> php -> mysql snafu (PHP)
- receiving data from a form in PHP? (PHP)
- HTML Form post to PHP? (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP/HTML Question. How to change frame after login?
- Next Thread: Help with chat script
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





