Page 1 of 1

[SOLVED] An array variable in a POST function? Dunno.

Posted: Sun Oct 02, 2005 3:34 pm
by Covenant
Okay I have this variable, $price[f]. How do I put that into a POST function (if that's what it's even called).

I tried $_POST[price[f]], $_POST['price[f]'], $_POST["price[f]"], why won't any work??

*EDIT* Basically it's a form with a changing amount of multiple values.
i.e.

Code: Select all

<input type=text name=price[1]>
<input type=text name=price[2]>
<input type=text name=price[3]>
<input type=text name=price[4]>
<input type=text name=price[5]>
and on the next page (after hitting the submit button) it edits a value in the DB for each one....

Code: Select all

$ep=mysql_query("SELECT * from members where name='$name[user]'");
  while($row = mysql_fetch_array($ep)) {
 $f=$row[id];
 $p=$_POST['price[$f]'];
  mysql_query("UPDATE members set price=$p where id='$f'");
                                                                }
Thanks in advance for any help,
Covenant 8)[/b]

Posted: Sun Oct 02, 2005 5:49 pm
by feyd
with

Code: Select all

<input type="text" name="price[0]" />

Code: Select all

print_r($_POST['price']);
will have your information

Posted: Sun Oct 02, 2005 6:13 pm
by Covenant
Okay that wasn't exactly my question, let me put it simply...

I have a variable, it is called $price[5]. How do I put that into a POST variable? Is it $_POST[$price[5]]???

Posted: Sun Oct 02, 2005 6:15 pm
by feyd

Code: Select all

echo '<input type="text" name="price[2]" value="'.$price[2].'" />';
you don't normally place data into the post data during the running of a script, but the submission of a page..

Posted: Sun Oct 02, 2005 6:41 pm
by Covenant
Oh oops! I just noticed my terrible wording....All this confusion is completely my fault.

Okay, I have this:

Code: Select all

<input type=text name=price[1]>
on the next page I want to SHOW that value.

Code: Select all

print "$_POST[price[1]] I guess????";
/* Which I know is not right... */
Basically, how do you show array values in a POST variable? zebra would be $_POST[zebra], doggy would be $_POST[doggy], but would be zebra[5]?
I am so sorry, man. :cry:

Posted: Sun Oct 02, 2005 6:56 pm
by feyd

Code: Select all

$_POST['zebra'][5]

Posted: Sun Oct 02, 2005 7:14 pm
by Covenant
PROBLEM SOLVED! I had been trying to fix that all night. Thank you so much, feyd!

Posted: Sun Oct 02, 2005 9:50 pm
by Jenk
A lot of confusion could have been saved if you actually read and tried what feyd first posted..