Having problems trying to pass hidden vars

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
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

Having problems trying to pass hidden vars

Post 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];   
...
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Having problems trying to pass hidden vars

Post by papa »

name='productid[]'

might help :)
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

Re: Having problems trying to pass hidden vars

Post by sjk1000 »

that's what I thought .. but no joy :?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Having problems trying to pass hidden vars

Post by papa »

You need to echo a p[] for every record in the array
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

Re: Having problems trying to pass hidden vars

Post 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
Attachments
hiddenvarsoutput.jpg
hiddenvarsoutput.jpg (23.69 KiB) Viewed 88 times
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Having problems trying to pass hidden vars

Post 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">";
}
Post Reply