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
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Mon Sep 11, 2006 8:09 am
I'm passing variables through from a from such as :
Code: Select all
<td align="center"><input type="text" name="<?php echo 'amount['.$srow['product_id'].']'; ?>" id="amount" size="3"></td>
<td align="center">£<input type="text" name="<?php echo 'buy_price['.$srow['product_id'].']'; ?>" id="buy_price" value="<?php echo ''.$srow['buy_price'].''; ?>" size="3"></td>
<td align="center"><input type="checkbox" name="<?php echo 'order['.$srow['product_id'].']'; ?>" id="order"></td>
<select name="<?php echo 'supplier['.$srow['product_id'].']'; ?>" id="supplier">
<?php if (isset($_POST['suppliers']))
{
$s2 = "SELECT * FROM suppliers WHERE id='".$_POST['suppliers']."'";
$sq2 = mysql_query($s2) or die ("Query $s2 Failed".mysql_error());
$sr2 = mysql_fetch_assoc($sq2);
?>
<option value="<?php echo $_POST['suppliers']; ?>"><?php echo $sr2['name']; ?></option>
<?
}
$s = "SELECT * FROM suppliers";
$sq = mysql_query($s) or die ("Query $s Failed".mysql_error());
while ($sr = mysql_fetch_assoc($sq))
{
?>
<option value="<?php echo $sr['id']; ?>"><?php echo $sr['name']; ?></option>
<?php
}
?>
</select>
They are then used (atm for testing), in the form:
Code: Select all
foreach($_POST['order'] as $orderID=>$orderValue)
{
$amount = current($_POST['amount']);
next($_POST['amount']);
$buy_price = current($_POST['buy_price']);
next($_POST['buy_price']);
$supplier = current($_POST['supplier']);
next($_POST['supplier']);
echo 'S='.$supplier.',A='.$amount.',P='.$buy_price.'<br />';
}
Which works fine for all but the select list. I can't get that to post through and work as the others in the above loop. Any ideas what i'm doing wrong?
Last edited by
rsmarsha on Tue Sep 12, 2006 2:35 am, edited 1 time in total.
GM
Forum Contributor
Posts: 365 Joined: Wed Apr 26, 2006 4:19 am
Location: Italy
Post
by GM » Mon Sep 11, 2006 8:46 am
I think the problem is here:
Code: Select all
<select name="<?php echo 'supplier['.$srow['product_id'].']'; ?>" id="supplier">
I think you are passing as a name for the select field something like "supplier[12345]".
Have a check of the html source of your page, to find how the name of your select field is actually rendered by php.
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 2:29 am
Yes it is, but i want it to do that, so it knows which product in the list that supplier is for. Also to make it post them into an array so i can work through them like the one above. For some reason i can't work out though it's not posting them as the others.
rsmarsha
Forum Contributor
Posts: 242 Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England
Post
by rsmarsha » Tue Sep 12, 2006 2:35 am
It seems to have started working for some strange reason.
So all is well.