Help needed to POST values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bbo
Forum Newbie
Posts: 4
Joined: Thu Feb 07, 2013 2:08 pm

Help needed to POST values

Post by bbo »

I have some problems with this code.

I'm trying to POST some values from the Select box and the Options to another page called "cart.php"

Here is the code:


Code: Select all

<form id="form1" name="form1" method="post" action="cart.php"  target="_self">
    
     <select name="sizetable" id="sizetable">
            <option  value="<?php echo $size_1?>"><?php echo $size_1?></option>
			<option  value="<?php echo $size_2?>"><?php echo $size_2?></option>
			<option  value="<?php echo $size_3?>"><?php echo $size_3?></option>
			<option  value="<?php echo $size_4?>"><?php echo $size_4?></option>
     </select>
   
   <input type="option" name="colsel" id="color_white" value="Hvid"/>
   <input type="option" name="colsel" id="color_black" value="Sort"/>
   <input type="option" name="colsel" id="color_grey" value="Grå" />
   <input type="option" name="colsel" id="color_lightred" value="Lys Rød";/>
   <input type="option" name="colsel" id="color_red" value="Rød" />
   <input type="option" name="colsel" id="color_pink" value="Pink" />
   <input type="option" name="colsel" id="color_blue"value="Blå" />
   <input type="option" name="colsel" id="color_lightblue" value="Lys Blå" />
   <input type="option" name="colsel" id="color_green" value="Grøn" />
   <input type="option" name="colsel" id="color_lime" value="Lime" />
   <input type="option" name="colsel" id="color_yellow" value="Gul" />
   <input type="option" name="colsel" id="color_orange" value="Orange" />
   <input type="option" name="colsel" id="color_purple" value="Lilla" />
   <input type="option" name="colsel" id="color_silver" value="Sølv" />
   <input type="option" name="colsel" id="color_gold" value="Guld" />
   <!--</form>-->
    

<!--   <div style=" z-index:100;position: absolute; left: 620px; top: 0px; width: 154px; height: 38px;" align="right"> -->
   
   <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />  
   <input type="hidden" name="sizetable" id="sizetable" value="<?php echo $size_1; ?>" /> 
   <input type="hidden" name="colsel" id="colsel" />
   <input type="image" name="imageField" id="imageField"  src="siteimages/legikurv.png"  title="Læg varen i indkøbskurver" /> 
   </form>
-------------------------------

In the cart.php I have this code:

Code: Select all

if (isset($_POST['pid'])) {
           $pid = $_POST['pid'];
           $pd = $_POST["sizetable"];
           $pd1 = $_POST["colsel"];
}
--------------------------------

I'm able to get the value from $_POST['pid'], but the other two values gives me nothing.
Can any one of you tell me what i'm doing wrong!

Regards Benny
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Help needed to POST values

Post by jraede »

First of all I don't think input type="option" is a valid type. Do you mean to use radio?

Second, you have hidden inputs at the bottom with the same name as those that are visible. The values in the hidden inputs will overwrite the values chosen in the "sizetable" and "colsel" fields. Why do you have those hidden fields?
bbo
Forum Newbie
Posts: 4
Joined: Thu Feb 07, 2013 2:08 pm

Re: Help needed to POST values

Post by bbo »

I actually just copied this piece of code: <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> and filled in some other names and id.

I actually thought that was the way to make this work.. I'm very new to php coding, but I'm still learning. :wink:

And you are right. I should have used radio instead of option.....
bbo
Forum Newbie
Posts: 4
Joined: Thu Feb 07, 2013 2:08 pm

Re: Help needed to POST values

Post by bbo »

I've made the changes you mentioned but it still not working
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Help needed to POST values

Post by social_experiment »

The syntax below should be amended like the example below; currently your option tags have no values which might be causing your problems. Stick to use single quotes for $_POST values like you did with $_POST['pid'].

Code: Select all

<option  value="<?php echo $size_4?>"><?php echo $size_4?></option>
// should be
<option  value="<?php echo $size_4; ?>"><?php echo $size_4; ?></option>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply