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

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
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

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

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

with

Code: Select all

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

Code: Select all

print_r($_POST['price']);
will have your information
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post 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]]???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$_POST['zebra'][5]
Covenant
Forum Newbie
Posts: 15
Joined: Sun Oct 02, 2005 3:30 pm

Post by Covenant »

PROBLEM SOLVED! I had been trying to fix that all night. Thank you so much, feyd!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

A lot of confusion could have been saved if you actually read and tried what feyd first posted..
Post Reply