Computing.Net > Forums > Web Development > PHP help... $_POST[var]

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP help... $_POST[var]

Reply to Message Icon

Name: delr2691
Date: March 23, 2005 at 13:07:17 Pacific
OS: Windows XP PRO
CPU/Ram: Intel Pentuim IV 2.6 Gh /
Comment:

Hey,
I have a problem,
i want to submit data in a db like this:
i have input fields which are randomly named...
but the name of the fields are stored into an array...
for example fields = array('field1', 'field2', 'etc');
and i want to take the fields value to enter it (the value) into a database...

i tried this:
foreach ($fields as $field) {
$enterField = $_POST["$field"];
$insert = "Insert into bla bla bla";
mysql_query($insert);
}
but this didn't work...
because it is trying to get the value of the field named "$field" which does not exist...!
help me with this one pliz...
thanx

---------------------
Diego Luces
delr_91@hotmail.com



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: March 23, 2005 at 15:01:19 Pacific
Reply:

hello,

Im not relly sure about this because you didn't tell us how'd you pass the field name from the form -> to the processor script... you sure the 'randomized' vars in the processor will have values?

---

you can use vars as an array index, just don't use quote -> $enterField = $_POST[$field];

---
Site of the Day


0

Response Number 2
Name: FBI Agent
Date: March 23, 2005 at 21:00:46 Pacific
Reply:

Laler i think has it. try this


$conn = mysql_connect($host, $user, $pass);
foreach ($fields as $field) {
$enterField = $_POST["$field"];
$insert = "Insert into table $enterField";
mysql_query($insert, $conn);
}

then of course you need to do the rest of it, but this should give you the basic database syntax

FBI Agent

AIM: EliteAssassin187


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP help... $_POST[var]

php help: submitting txt fields www.computing.net/answers/webdevel/php-help-submitting-txt-fields/2871.html

php help needed www.computing.net/answers/webdevel/php-help-needed/2399.html

Help modify some JavaScript/HTML www.computing.net/answers/webdevel/help-modify-some-javascripthtml/2761.html