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:

<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):&nbsp;<?php print($sizeLp);?></input><br/>
//$sizeSp is the item's small size price
<input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S):&nbsp;<?php print($sizeSp);?></input><br/><br/>
<input type="submit" value="Submit"></input>
</form>

Here is my bar.php code:

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 $_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:

$_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 :)

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:

<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):&nbsp;<?php print($sizeLp);?></input><br/>
//$sizeSp is the item's small size price
<input type="radio" name="sizeS" value="<?php echo $sizeSp; ?>">Price(S):&nbsp;<?php print($sizeSp);?></input><br/><br/>
<input type="submit" value="Submit"></input>
</form>

Here is my bar.php code:

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.