Jump to content

problem with putting in URL


swissbeets

Recommended Posts

I am trying to save the shirt size and then bring it back up in the shopping cart page, but i cannot get it to come up in the URL

 

this is the function that displays the drop down menu,  the array is ('S','M','L','XL')  i cannot figure out what variable to use or how to use it

 

function showOptionsDrop($array, $active, $echo=true){

        $string = '';

 

        foreach($array as $k => $v){

            $s = ($active == $k)? ' selected="selected"' : '';

            $string .= '<option value="'.$k.'"'.$s.'>'.$v.'</option>'."\n";   

        }

 

        if($echo)  echo $string;

        else        return $string;

    }

 

 

this is my hyperlink to save this information

 

 

cho "<a href=\"shoppingcart.php?prod=".urlencode($row['product_id'])."?&size=$string[$k]"."?&action=add\">Add to Shopping Cart"."</a>";

 

 

i will then make a GET and display the size in the shopping cart but my URL will not work

 

do i have to do something witth the session?  any help is greatly appreciated

Link to comment
Share on other sites

You have to get the value of the dropdown via javascript if you want to do it this way.

 

You are better off just wrapping each "item" in a form. Make a hidden input field with the name prod and the value of $row['product_id'], you already have the select menu for size, and then just add another hidden input with name action and value of add.

 

Make sense?

Link to comment
Share on other sites

kind of i do not know how to use a hidden field but can find out

 

but as for the rest, product id, and action are already being passed to the next page,

 

i have up to this far working but then realized i needed to put sizes in there 

 

any chance you could clarify please i am still very new but want to learn

Link to comment
Share on other sites

All the other values work fine because the values are already known while PHP is building the page. The size though, is not. JavaScript is messy and, if someone has it disabled, they can't buy something from your site....

 

Instead, do something like this:

<?php
while($row=mysql_fetch_assoc($result)){
?>
<form method="GET" action="shoppingcart.php">
  <input type="hidden" name="prod" value="<?php echo urlencode($row['product_id']); ?>" />
  <input type="hidden" name="action" value="add" />
<?php showOptionsDrop($array,'M'); ?>
  <input type="submit" value="Add to Shopping Cart" />
</form>
<?php
  }
?>

Link to comment
Share on other sites

does this go inside my first while loop? sorry i am very new to this ?

 

this is my current while loop

 

while($row = mysql_fetch_array($product_set)){

 

 

 

    echo "<p>";

    echo $row['product_name']."<br />";

    echo "$".$row['product_price']."<br />"."<br />";

    show_picture($row); 

echo "<br/>";

 

 

echo  "Size: ";  ?><p>

<select name="size">

<?php

$size = array('Select','S','M','L','XL');

showOptionsDrop($size);

?>

</select>

</p> <?php

               

 

echo "<a href=\"shoppingcart.php?prod=".urlencode($row['product_id'])."?&size=['$size']"."?&action=add\">Add to Shopping Cart"."</a>";

 

 

your saying i should make it a form with hidden values rather than even use a session? 

Link to comment
Share on other sites

nothing in your code here has anything to do with sessions...but what i'm saying, is the above code should be changed to:

 

<?php
while($row = mysql_fetch_array($product_set)){
?>
<form method="GET" action="shoppingcart.php">
  <input type="hidden" name="prod" value="<?php echo $row['product_id']; ?>" />
  <input type="hidden" name="action" value="add" />
  <p>
    <?php echo $row['product_name']; ?><br />
    $<?php echo $row['product_price']; ?><br /><br />
    <?php show_picture($row); ?><br />
    Size: 
    <p>
      <select name="size">
        <?php showOptions(array('Select','S','M','L','XL')); ?>
      </select>
    </p>
    <input type="submit" value="Add to Shopping Cart" />
  </p>
</form>
<?php
}  
?>

Link to comment
Share on other sites

ok i understand what your saying with this and did so, but  it is only displaying the top product and and not displaying a submit button        these variables will be POSTed and then i can easily GET them at a later date is this correct?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.