2 Replies - 5950 Views - Last Post: 03 January 2008 - 01:04 PM Rate Topic: -----

#1 didgy58   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 246
  • Joined: 23-October 07

passing a select value to a php variable

Posted 03 January 2008 - 06:21 AM

i seem to be having trouble.. when the user clicks the purchase item button on my page below


i would like to be able to add a different quantity at the moment its set to 1, so when the user selects 3 it would add 3 to the cart the problem is how do i get the selected value to be stored in a variable

would it be something like


here is my code for the page

i have passed a number over easily by manually putting it in but when i try and put the select value it doesnt wanna know


//using this variable to track down any possible problems

//validating that a product id has been passed to this page
if (isset($_GET['pid'])){

//creating the query to retrive the information required
$query="select * from Product where product_id=" .$pid;
//the print id was typecast to int for security purposes

if (mysql_num_rows($result)==1){
while ($row = mysql_fetch_array($result)){

include ('./include/header.html');

//start the html page


//build the main content of the page

echo "<div id='main2'>";
echo "<fieldset id='fieldresult'>";

//Display a header
echo "<div id='ablue'>";
echo "<div id='buyboxDivId' class='buying'>
	<table id='buyboxTable' border='0' cellspacing='0' cellpadding='0' class='buyBox' width='215'>
	  <td width='190' class='topLeft'>

		<table cellspacing='0' cellpadding='0' border='0' align='center'>
			<td align='center' style='text-align: center;'>

<div style='padding: 4px 0px;'>

<b>Price:</b> <b>$$price</b><br />In stock<br />Dispatched from and sold by <b>Quo-Vadis.me.uk</b>

<div align='center' style='margin-bottom: 4px;'><b class='small'>Quantity:&nbsp;</b><select name='quantity'><option value='1' selected>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option></select></div><input type='hidden' name='maap_bb_qty_limit' value='30' />

<span id='addToCartSpan'>
<a href='add_cart.php?pid=$pid&quant=2'><input type='image' src='http://g-ecx.images-amazon.com/images/G/02/nav2/dp/btn-atc._V45449963_.gif'  width='166' alt='Add to Shopping Basket' name='submit.add-to-cart' height='27' border='0' /></a>
<br />	  
	  <td width='13' class='topRight'>&nbsp;</td>

	  <td class='bottomLeft'>&nbsp;</td>
	  <td class='bottomRight' height='12'>&nbsp;</td>

echo "<table id='resultstab' border='0' >

<tr><td rowspan='4'><img src='../images/$pic' border=0 alt=''></td>
<td>Product Name</td><td><b><font size='+1'>$page_title</font></b></td>
</tr><tr><td>Price : $ </td><td>$price</td></tr><tr>
<td>Photo Support </td><td>$ps</td></tr><tr><td>Power For Video</td><td>$pv</td></tr></table>";
echo '</fieldset>';

echo '</div>';


if ($problem){
echo '<div align=\"center/"> This Page has been accessed in error! </div>';

include ('./include/footer.html');

and yes i borrowed the blue box from amazon, thought it looked nice lol..

thanks again


Is This A Good Question/Topic? 0
  • +

Replies To: passing a select value to a php variable

#2 dontKnowJava   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 221
  • Joined: 29-September 07

Re: passing a select value to a php variable

Posted 03 January 2008 - 12:46 PM

try putting your options in a form and get values from $_POST array on submit
Was This Post Helpful? 0
  • +
  • -

#3 JosephGan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-December 07

Re: passing a select value to a php variable

Posted 03 January 2008 - 01:04 PM

It would not be good if the user select on the number and it get directly updated to the database.

U could have a submit button as what dontKnowJava has stated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1