Page 2 of 3

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

Posted: Mon Feb 02, 2009 12:22 pm
by fionaom87
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

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

Posted: Mon Feb 02, 2009 12:32 pm
by Skoalbasher
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

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]'];
 
I hope this makes sense, i'm at work right now so don't have time to write something out completely.

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

Posted: Mon Feb 02, 2009 12:42 pm
by fionaom87
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.

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

Posted: Mon Feb 02, 2009 12:50 pm
by Skoalbasher
If you have 1 hidden field named "windowtype[]" for each text named "quantity[]" you can do something like this

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 ++;
  }
}
 
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.

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

Posted: Mon Feb 02, 2009 12:58 pm
by fionaom87
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

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

Posted: Mon Feb 02, 2009 1:10 pm
by Skoalbasher
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

Posted: Mon Feb 02, 2009 1:13 pm
by fionaom87
that would be brillant really appreciate it!

Thanks

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

Posted: Mon Feb 02, 2009 1:30 pm
by watson516
Providing you are using a mysql db, this might work (untested)

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>
proccess.php

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
}
?>
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

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

Posted: Mon Feb 02, 2009 1:37 pm
by jaoudestudios
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?

Re: Passing hidden variables PLEASE HELP!

Posted: Mon Feb 02, 2009 2:05 pm
by Skoalbasher
So, keep page 1 the way it is

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 ++;
  }
}
 
Page 3

Code: Select all

 
echo "User has selected ".$_SESSION['quantity'][0]." ".$_SESSION['windowtype'][0]."'s"; 
 
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.

Re: Passing hidden variables PLEASE HELP!

Posted: Mon Feb 02, 2009 2:35 pm
by fionaom87
//////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

Re: Passing hidden variables PLEASE HELP!

Posted: Mon Feb 02, 2009 2:42 pm
by Skoalbasher

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 ++;
  }
}
?>
 
 
Oops! Change a$ to $a on line 71.

Re: Passing hidden variables PLEASE HELP!

Posted: Mon Feb 02, 2009 3:06 pm
by fionaom87
<?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

Re: Passing hidden variables PLEASE HELP!

Posted: Mon Feb 02, 2009 3:45 pm
by watson516
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!

Posted: Mon Feb 02, 2009 3:47 pm
by s.dot
top of the script..

Code: Select all

ini_set('display_errors', 'On');
error_reporting(E_ALL);