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
sjk1000
Forum Commoner
Posts: 26 Joined: Tue Nov 11, 2008 8:50 am
Post
by sjk1000 » Tue Dec 02, 2008 6:57 am
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];
...
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Dec 02, 2008 7:51 am
name='productid[]'
might help
sjk1000
Forum Commoner
Posts: 26 Joined: Tue Nov 11, 2008 8:50 am
Post
by sjk1000 » Tue Dec 02, 2008 8:00 am
that's what I thought .. but no joy
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Dec 02, 2008 8:03 am
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
Post
by sjk1000 » Tue Dec 02, 2008 8:27 am
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
Attachments
hiddenvarsoutput.jpg (23.69 KiB) Viewed 88 times
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Tue Dec 02, 2008 8:29 am
Niet,
Loop your actual html form.
$prod = array(1,2,3);
foreach($prod as $hidden_shiet) {
echo "<hidden_bla name=p[] value=$hidden_shiet">";
}