1,105,447 Community Members

GET from dropdown list

Member Avatar
qwertpink
Newbie Poster
14 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all,

Im trying to add sizes to the cart. However, i cant pass size over. please help.

$result = $db->query($sql);
$output[] = '<ul>';

while ($row = $result->fetch()) { 

  $output[] = '<br><font color="837F77"size="6">'.$row['name'].' </font><br></br> S$'.$row['price'].'<br></br>';

 $output[] = '<select name="size">
<option disabled="disabled" selected value="NA" >Size</option>';

     if ($row[small_qty]== 0){  
  $output[] = ' <option disabled="disabled" value="NA" >Small</option>';
}else { 
  $output[] = '<option value="s">Small</option>';
 } 
      if ($row[medium_qty]== 0){  
  $output[] = ' <option disabled="disabled"  value="NA" >Medium</option>';
 }else {
  $output[] = '<option value="m">Medium</option>';
 } 
      if ($row[large_qty]== 0){  
  $output[] = ' <option disabled="disabled"  value="NA" >Large</option>';
 }else {
 $output[] = ' <option value="l">Large</option>';
 } 
 $output[] = '</select>';

    $output[] = '<br></br><a href="cart.php?action=add&product_id='.$row['product_id'].'&p='.$size.'" value="Submit"> <img src="image/addbutton.png" border="0" /></a></a> 
</li>';

}
$output[] = '</ul>';
echo join('',$output);

GET

<?php

// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
$size= $_GET['p'];

$size1 = $_POST['size'];

//if there is an product_id and that product_id doesn't exist display an error message
if($product_id && !productExists($product_id)) {
    die("Error. Product Doesn't Exist");
}

echo $size;
echo $action ;
echo $size1 ;
echo $_GET['product_id'];
switch ($action) {
    case 'add':
        if ($cart) {
            $cart .= ','.$_GET['product_id'];

        } else {
            $cart = $_GET['product_id'];

        }
        break;

Any other idea?
Help is much appreciated, im sorry , im still learning

Member Avatar
EvolutionFallen
Posting Pro
504 posts since Aug 2009
Reputation Points: 107 [?]
Q&As Helped to Solve: 108 [?]
Skill Endorsements: 8 [?]
 
0
 

Is there a reason you are using

<select>
    <option></option>
</select>
<a href="..."></a>

Instead of

<form>
    <select>
        <option></option>
    </select>
    <input type="submit [or button]" />
</form>

? The second would make things easier on you. The way you're doing it now requires JavaScript to pass the value correctly. Putting $size into the URL in the <a> tag won't work, because $size has no value there and will not change based on your dropdown selection.

Member Avatar
qwertpink
Newbie Poster
14 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Yes ! finally i can pass the size .
Thank you so much EvolutionFallen .

Question Answered as of 1 Year Ago by EvolutionFallen
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: