Passing hidden variables PLEASE HELP!

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

fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Passing hidden variables PLEASE HELP!

Post by fionaom87 »

HEY,

basically im creating an online shopping cart and i want for customers to input the quantity that they want. i am using hidden variables but i dont know how to use an if statement so for e.g. if a person enters a quantity on a specific product that i can carry this variable to the end.i dont want all the products to be carried to the end if you know what i mean.



// this is my input box

<div id="box25"><img src="FYP/img19.jpg" alt="Windows"/>
<label> Bay Windows </label>
</div>
<div id="box26"><input type="text" name="quantity8" size="1"><label> Quantity</label></div>

// if input an quantity specifically in this input box and not the others ones??
i only want to pass the value that is inputed in that specific input box.

im really stuck please HELP

THanks

Fiona.
Last edited by pickle on Mon Feb 02, 2009 1:39 pm, edited 1 time in total.
Reason: Changed the subject line
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by mattpointblank »

$_POST['quantity8'] will give you the number they entered, but honestly, no offence - if you don't know that kind of basic level stuff, I wouldn't recommend writing a shopping cart script.
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

ya just started learning php and mysql a month ago. i know my questions are basic.

I have a number of different input boxes on a page, i want the value of the specific input box that a customer enters a quantity brought forward to the next page in the form of a hidden variable.


I think i must use some sort of an if statement so when a value is entered only that variale is carried forward. Any help would be great i am really stuck!!!!!!!!!!!!!!

<div id="box23"><img src="FYP/img18.jpg" alt="Windows"/>
<label> Bow Windows </label>
</div>
<div id="box24"><input type="text" name="quantity7" size="1"> <label> Quantity</label></div>

<div id="box25"><img src="FYP/img19.jpg" alt="Windows"/>
<label> Bay Windows </label>
</div>
<div id="box26"><input type="text" name="quantity8" size="1" selected="selected"><label> Quantity</label></div>

<div id="box27"><img src="FYP/img20.jpg" alt="Windows"/>
<label> Speciality Type Windows </label>
</div>
<div id="box28"><input type="text" name="quantity9" size="1" selected="selected"><label> Quantity</label></div>

<div id="box29"><img src="FYP/img21.jpg" alt="Windows"/>
<label> Vertical Slider Windows</label>
</div>
<div id="box30"><input type="text" name="quantity10" size="1" selected="selected"><label> Quantity</label></div>

<div id="box31"><img src="FYP/img22.jpg" alt="Windows"/>
<label> Casement Windows </label>
</div>
<div id="box32"><input type="text" name="quantity11" size="1" selected="selected"><label> Quantity</label></div>

<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity12" size="1" selected="selected"><label> Quantity</label></div>


<input type="submit" value="Submit Details"/>
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by mattpointblank »

If your form goes to a specific page (eg <form action="process.php"> then on that page, you can use the code I posted above to get the value.
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

but how will i know what product the customer will choose

e.g. if a customer chooses bay view window quantity 4. i want that brought forward as a hidden variable to the next page.

THanks
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

if it helps i have this on my next page

$quantity7 = htmlentities ($_POST['quantity7']);
$quantity8 = htmlentities ($_POST['quantity8']);
$quantity9 = htmlentities ($_POST['quantity9']);
$quantity10 = htmlentities ($_POST['quantity10']);
$quantity11 = htmlentities ($_POST['quantity11']);
$quantity12 = htmlentities ($_POST['quantity12']);
// only that not all this values will be filled in only one of them
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by Skoalbasher »

So you're saying they enter the quantity, then on the next page, it's another form but this time the quantity is going to be in a hidden field instead of a text input?

Is this correct?
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

yes the next page is another selection process its the following page that i want the quantity to be displayed e.g.


Your have filled in the following details;

Quantity 4

// this is my code on that page

<?php
$name = htmlentities($_POST['name']);
$address = htmlentities($_POST['address']);
$telephoneno = htmlentities($_POST['telephoneno']);
$housetype = htmlentities($_POST['housetype']);
$quantity1 = htmlentities ($_POST['quantity1']);
$quantity2 = htmlentities ($_POST['quantity2']);
$quantity3 = htmlentities ($_POST['quantity3']);
$quantity4 = htmlentities ($_POST['quantity4']);
$quantity5 = htmlentities ($_POST['quantity5']);
$quantity6 = htmlentities ($_POST['quantity6']);
$quantity7 = htmlentities ($_POST['quantity7']);
$quantity8 = htmlentities ($_POST['quantity8']);
$quantity9 = htmlentities ($_POST['quantity9']);
$quantity10 = htmlentities ($_POST['quantity10']);
$quantity11 = htmlentities ($_POST['quantity11']);
$quantity12 = htmlentities ($_POST['quantity12']);
$iname = htmlentities($_POST['iname']);
$style = htmlentities($_POST['style']);
$measurement = htmlentities($_POST['measurement']);
$quantity = htmlentities($_POST['quantity']);
$colour = htmlentities($_POST['colour']);
?>


Quantity: <?php echo $quantity; ?><BR>


but this is not working as i only want wat the person inputed to appear at the label quantity.
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by Skoalbasher »

The total quantity is what you want?
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

well yes the totally quantity of what the customer inputs.

THanks
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by Skoalbasher »

You could make your input box an array

Code: Select all

 
// like this
 
<div id="box31"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<div id="box32"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<div id="box33"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
 
On your other page

Code: Select all

 
$totalquantity = $_POST['quantity'];
 
$newtotal = array_sum($totalquantity);
 
echo $newtotal;
 
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

following error occurs


Warning: array_sum() [function.array-sum]: The argument should be an array in C:\wamp\www\inventory.php on line 50

This is line 50

<?php
$totalquantity = $_POST['quantity'];

$newtotal = array_sum($totalquantity);
?>


/////previous page has the following

<div id="box23"><img src="FYP/img18.jpg" alt="Windows"/>
<label> Bow Windows </label>
</div>
<div id="box24"><input type="text" name="quantity7" size="1"selected="selected"> <label> Quantity</label></div>

<div id="box25"><img src="FYP/img19.jpg" alt="Windows"/>
<label> Bay Windows </label>
</div>
<div id="box26"><input type="text" name="quantity8" size="1" selected="selected"><label> Quantity</label></div>

<div id="box27"><img src="FYP/img20.jpg" alt="Windows"/>
<label> Speciality Type Windows </label>
</div>
<div id="box28"><input type="text" name="quantity9" size="1" selected="selected"><label> Quantity</label></div>

<div id="box29"><img src="FYP/img21.jpg" alt="Windows"/>
<label> Vertical Slider Windows</label>
</div>
<div id="box30"><input type="text" name="quantity10" size="1" selected="selected"><label> Quantity</label></div>

<div id="box31"><img src="FYP/img22.jpg" alt="Windows"/>
<label> Casement Windows </label>
</div>
<div id="box32"><input type="text" name="quantity11" size="1" selected="selected"><label> Quantity</label></div>

<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity12" size="1" selected="selected"><label> Quantity</label></div>


<input type="submit" value="Submit Details"/>
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by Skoalbasher »

it's because you're not passing arrays. You should change

Code: Select all

 
<div id="box24"><input type="text" name="quantity7" size="1"selected="selected"> <label> Quantity</label></div>
 
// change name="quantity7" to quantity[]
// like this
 
<div id="box23"><img src="FYP/img18.jpg" alt="Windows"/>
<label> Bow Windows </label>
</div>
<div id="box24"><input type="text" name="quantity[]" size="1"selected="selected"> <label> Quantity</label></div>
 
<div id="box25"><img src="FYP/img19.jpg" alt="Windows"/>
<label> Bay Windows </label>
</div>
<div id="box26"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
 
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by fionaom87 »

ya thats brill worked a charm

just one more question,

<label> Bow Windows </label>

can i put <label value ="BowWindows" </label>
so i can pass this on too?

Thanks
User avatar
Skoalbasher
Forum Contributor
Posts: 147
Joined: Thu Feb 07, 2008 8:09 pm

Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1

Post by Skoalbasher »

To be honest with you, i'm not sure. maybe a hidden field right below it.

Code: Select all

 
<input type="hidden" name="windowtype[]" value="bay windows">
 
Post Reply