Passing hidden variables PLEASE HELP!
Moderator: General Moderators
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
sorry again but i messed around with and that error came back again this is what i have now.
<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<!-- Passing of hidden variables-->
<INPUT TYPE="hidden" name="quantity[]" VALUE="<?php echo $quantity[]; ?>">
////my next page
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
<!-- Passing of hidden variables-->
<INPUT TYPE="hidden" name="quantity[]" VALUE="<?php echo $quantity[]; ?>">
and my page after that
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
Quantity: <?php echo $newtotal; ?><BR>
?>
is it possible to do this or should i stick to just passing from one direct page to another
<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<!-- Passing of hidden variables-->
<INPUT TYPE="hidden" name="quantity[]" VALUE="<?php echo $quantity[]; ?>">
////my next page
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
<!-- Passing of hidden variables-->
<INPUT TYPE="hidden" name="quantity[]" VALUE="<?php echo $quantity[]; ?>">
and my page after that
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
Quantity: <?php echo $newtotal; ?><BR>
?>
is it possible to do this or should i stick to just passing from one direct page to another
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
Ok, your hidden type is the same name as your text boxes, which isn't what you should do.
It'd be something like this
so if Tilt and Turn was the first type selected, you'd pull it like
I hope this makes sense, i'm at work right now so don't have time to write something out completely.
It'd be something like this
Code: Select all
<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<!-- Passing of hidden variables-->
<INPUT TYPE="hidden" name="windowtype[]" VALUE="Tilt and Turn">
so if Tilt and Turn was the first type selected, you'd pull it like
Code: Select all
$type1 = $_POST['windowtype[0]'];
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
for some reason now my quantity values arent working anymore either.
page1////where i input my quantity
<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
page2//
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
page3//
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
Quantity: <?php echo $newtotal; ?><BR>
i want to drag my quantity value from page 1 to page 3.
thank u for your patience and time.
page1////where i input my quantity
<div id="box33"><img src="FYP/img23.jpg" alt="Windows"/>
<label> Tilt and Turn Windows </label>
</div>
<div id="box34"><input type="text" name="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
page2//
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
page3//
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
Quantity: <?php echo $newtotal; ?><BR>
i want to drag my quantity value from page 1 to page 3.
thank u for your patience and time.
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
If you have 1 hidden field named "windowtype[]" for each text named "quantity[]" you can do something like this
On a side note, I may be wrong.. but I don't think you can send $_POST data to 1 page from another without using a form. You could use a $_SESSION variable instead.
Code: Select all
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$i = 0;
foreach($qt as a$)
{
if($a[$i])
{
echo "User selected ".$a[$i]." ".$wt[$i]."'s";
$i ++;
}
}
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
ya sounds like what exactly what i want but this occured when i put
this in page 3
<?php
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$i = 0;
foreach($qt as a$) //line 89
{
if($a[$i])
{
echo "User selected ".$a[$i]." ".$wt[$i]."'s";
$i ++;
}
}
?>
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\inventory.php on line 89
(ive highlighted line 89).
page 2 has this now at the end
<INPUT TYPE="hidden" name="windowtype[]" VALUE="Tilt and Turn">
page 3 has this at the top
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
<?php
$type1 = $_POST['windowtype[0]'];
?>
thanks
this in page 3
<?php
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$i = 0;
foreach($qt as a$) //line 89
{
if($a[$i])
{
echo "User selected ".$a[$i]." ".$wt[$i]."'s";
$i ++;
}
}
?>
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\inventory.php on line 89
(ive highlighted line 89).
page 2 has this now at the end
<INPUT TYPE="hidden" name="windowtype[]" VALUE="Tilt and Turn">
page 3 has this at the top
<?php
$totalquantity = $_POST['quantity'];
$newtotal = array_sum($totalquantity);
?>
<?php
$type1 = $_POST['windowtype[0]'];
?>
thanks
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
I'm sorry, I know you're trying to work on this. I think I know what you need, I'll try and get something working on my lunch break. ugh.
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
that would be brillant really appreciate it!
Thanks
Thanks
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
Providing you are using a mysql db, this might work (untested)
items
proccess.php
If you're not using a db, you could probably use sessions instead.
When you want to display the contents of the shopping cart, you could just query the cart table for every entry with the logged in user's username
items
Code: Select all
<div class="content">
<form action="process.php" method="POST">
<div class="item">
<img src="item.jpg" alt="Sliding Windows" />
<h3>Sliding Windows</h3>
<p>
Quanity: <input type="text" name="quant[]" />
</p>
<input type="hidden" name="item[]" value="1" />
</div>
<div class="item">
<img src="item.jpg" alt="Broken Windows" />
<h3>Broken Windows</h3>
<p>
Quanity: <input type="text" name="quant[]" />
</p>
<input type="hidden" name="item[]" value="2" />
</div>
<div class="item">
<img src="item.jpg" alt="Tilt and Turn Windows" />
<h3>Tilt and Turn Windows</h3>
<p>
Quanity: <input type="text" name="quant[]" />
</p>
<input type="hidden" name="item[]" value="3" />
</div>
<div class="add">
<input type="submit" value="Add To Cart" />
</div>
</form>
</div>Code: Select all
<?php
session_start();
if(isset($_POST['item'])
{
foreach ($_POST['quant'] as $key => $value)
{
if($value)
{
//Add this item to the shopping cart table
$item=htmlentities($_POST['item'][$key]);
$quant=(int)$_POST['quant'][$key];
$q="INSERT INTO cart(cart_user,cart_item,cart_quant) VALUES('{$_SESSION['user']}','$item',$quant)";
if(mysql_query($q))
{
header('Location: index.html');
}else{
header('Location: index.html?err=1');
}
}
}
}else{
header('Location: index.html'); //This page was visited directly
}
?>When you want to display the contents of the shopping cart, you could just query the cart table for every entry with the logged in user's username
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Passing hidden variables PLEASE HELP!!!!!!!!!!!!!!!!!!1
Download a shopping cart, there are loads of opensource ones out there.
I have not tried any myself, but I think you would make more progress. As you will still need to build in a lot more features. No offense, but I hope you are not planning on doing credit cards?
I have not tried any myself, but I think you would make more progress. As you will still need to build in a lot more features. No offense, but I hope you are not planning on doing credit cards?
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Passing hidden variables PLEASE HELP!
So, keep page 1 the way it is
this is on page 2
Page 3
Should print something like "User has selected 23 Bay Window's"
EDIT: I don't have anything to check this on while i'm here at work.
this is on page 2
Code: Select all
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$_SESSION['windowtype'] = array();
$_SESSION['quantity'] = array();
$i = 0;
foreach($qt as a$)
{
if($a[$i])
{
$_SESSION['windowtype'][$i] = $wt[$i];
$_SESSION['quantity'][$i] = $a[i];
$i ++;
}
}
Code: Select all
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s";
EDIT: I don't have anything to check this on while i'm here at work.
Re: Passing hidden variables PLEASE HELP!
//////page 1
<div id="box31"><img src="FYP/img22.jpg" alt="Windows"/>
<label> Casement Windows </label>
</div>
<div id="box32"><input type="text" name="quantity[]" 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="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<input type="submit" value="Submit Details"/>
//page 2
<?php
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$_SESSION['windowtype'] = array();
$_SESSION['quantity'] = array();
$i = 0;
foreach($qt as a$) // line 71
{
if($a[$i])
{
$_SESSION['windowtype'][$i] = $wt[$i];
$_SESSION['quantity'][$i] = $a;
$i ++;
}
}
?>
///page 3
<?PHP
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s";
?>
following error comes up
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\page2.php on line 71
<div id="box31"><img src="FYP/img22.jpg" alt="Windows"/>
<label> Casement Windows </label>
</div>
<div id="box32"><input type="text" name="quantity[]" 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="quantity[]" size="1" selected="selected"><label> Quantity</label></div>
<input type="submit" value="Submit Details"/>
//page 2
<?php
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$_SESSION['windowtype'] = array();
$_SESSION['quantity'] = array();
$i = 0;
foreach($qt as a$) // line 71
{
if($a[$i])
{
$_SESSION['windowtype'][$i] = $wt[$i];
$_SESSION['quantity'][$i] = $a;
$i ++;
}
}
?>
///page 3
<?PHP
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s";
?>
following error comes up
Parse error: parse error, expecting `T_PAAMAYIM_NEKUDOTAYIM' in C:\wamp\www\page2.php on line 71
- Skoalbasher
- Forum Contributor
- Posts: 147
- Joined: Thu Feb 07, 2008 8:09 pm
Re: Passing hidden variables PLEASE HELP!
Code: Select all
<?php
$qt = $_POST['quantity'];
$wt = $_POST['windowtype'];
$_SESSION['windowtype'] = array();
$_SESSION['quantity'] = array();
$i = 0;
foreach($qt as $a) // <---- change here a$ should actually be $a (line 71)
{
if($a[$i])
{
$_SESSION['windowtype'][$i] = $wt[$i];
$_SESSION['quantity'][$i] = $a[i];
$i ++;
}
}
?>
Re: Passing hidden variables PLEASE HELP!
<?PHP
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s";
?>
everything seems fine im not sure whats causing the problem
it is only printing User has selected 's
Thanks very much for your help
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s";
?>
everything seems fine im not sure whats causing the problem
it is only printing User has selected 's
Thanks very much for your help
Re: Passing hidden variables PLEASE HELP!
have you started the session?
Code: Select all
<?php
//The very top of the page, no output before this
session_start();
?>Re: Passing hidden variables PLEASE HELP!
top of the script..
Code: Select all
ini_set('display_errors', 'On');
error_reporting(E_ALL);Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.