Page 1 of 1

Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 6:57 am
by sjk1000
Hi all
I'm trying to pass 5 hidden arrays from script 1 to script 2 below but all I'm getting from the echos in script 2 are 'A's, short for 'Array'. There's something stupidly obvious that I'm missing - probably from the form itself - but I can't figure out what it is. Any help is very much appreciated.
Thanks, Steve

script 1:

Code: Select all

    print ("<form action='http://www.mywebsite.co.uk/catalog/index.php?main_page=seller_confirmation' method='post'>");
    print ("<div style='float:right' > <input class='mybtn' SIZE='5' type='submit' name='confirm_db_update' value='Confirm'> </div>"); 
    print ("<input type='hidden' name='productid' id='productid' value= ".$productid. "/>");
    print ("<input type='hidden' name='qty' id='quantity' VALUE = ".$qty. "/>");
    print ("<input type='hidden' name='price' id='price' VALUE =".$price. "/>");
    print ("<input type='hidden' name='shipping' id='shipping' VALUE =".$shipping. "/>");
    print ("<input type='hidden' name='sdprice' id='sdprice' VALUE =".$sdprice. "/>");
    print ("</form>");
script 2:

Code: Select all

if(isset($_POST['confirm_db_update'])) 
    {
    $productid=$_POST['productid'];  
    $qty=$_POST['qty'];
    $price=$_POST['price'];
    $shipping=$_POST['shipping'];
    $sdprice=$_POST['sdprice'];
     
    echo $productid[0];
    echo $qty[0];
    echo $price[0];
    echo $shipping[0];
    echo $sdprice[0];   
...

Re: Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 7:51 am
by papa
name='productid[]'

might help :)

Re: Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 8:00 am
by sjk1000
that's what I thought .. but no joy :?

Re: Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 8:03 am
by papa
You need to echo a p[] for every record in the array

Re: Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 8:27 am
by sjk1000
Hi Papa
if you mean use a loop such as:

Code: Select all

    print("<TABLE class='seller' ALIGN=center VALIGN=TOP width='850 '>\n");  
    print("<TR  align=center><TH>Prod ID</TH><TH>Title</TH><TH>Qty</TH><TH>Price</TH><TH>Shipping</TH><TH>SD Price</TH></TR>");
    for($x=0; $x<count($_POST['productid']); $x++)
        {       
        if($qty[$x]!= ''||$price[$x] != ''||$shipping[$x] != ''||$sdprice[$x] != '')
        {           
        print("<TR><TD>" .$productid[$x]. " </TD><TD> " .query_get_product_name($productid, $x). "</TD><TD>".$qty[$x]."</TD><TD>" .$price[$x]. "</TD><TD>" .$shipping[$x]. "</TD><TD>" .$sdprice[$x]. "</TD></TR>");
        }
        }
    print ("</TABLE>\n");   
when the vars have been passed as hidden, the table output is as shown in the screenshot. ie identical to the print_r result. I think everything on the form handler side has been tested and proven to work on other pages so I'm assuming that it must be something in the form itself.
Feels like I've been looking at this for hours 8O

Re: Having problems trying to pass hidden vars

Posted: Tue Dec 02, 2008 8:29 am
by papa
Niet,

Loop your actual html form.

$prod = array(1,2,3);

foreach($prod as $hidden_shiet) {
echo "<hidden_bla name=p[] value=$hidden_shiet">";
}