Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from $_POST and putting them into table

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
On my site I have a form that is generated automatically from database. What I want is when user submits the form to take users results and display them inside the table.

I know I can get all results from the form from $_POSt but how can I loop through them to insert the info into a table. Can anybody help?

Here is the HTML example of what I want to achieve:
 
You can use the foreach loop to iterate arrays.
Code:
foreach($_POST as $key=>$value){
  # now you have fieldname as key and the value
  echo("$key is $value");
}
 
DRJ478,

Thank you for your reply. I got to this point myself, but I can't move further. I need to take those values and display them inside the table. Just like I showed in my HTML example. Can you help?
 
When you produce the newtable.html you are printing "Some data #" in the table cells.
Replace that with the POST value:
The form:
Code:
<td><input type=&quot;text&quot; name=&quot;T84&quot; size=&quot;20&quot; value=&quot;Some Data 15&quot;></td>

The newtable:
Code:
<td><?php echo $_POST['T84'];?</td>



 
Well, unfortunately, I can't do that, because all of my fields on the first page are generated dynamically from database, so I can't reference any fields because I simply can't predict which field is displayed. There got to be some other way!
 
So,

when you generate the first page from the DB setup a hidden field that includes all the name attributes delimited.
Create an array $varnames and add everytime you create an input field:
Code:
$varArray[] = ... # assign the name
Then implode with the delimiter:
Code:
$varnames = implode(',',$varArray);
echo &quot;<input type=\&quot;hidden\&quot; name=\&quot;varnames\&quot; value=&quot;$varnames&quot;>

You can then loop through the posted varnames and assign the data that way, no matter what's in there.
 
Well,

I did that already. If I &quot;echo&quot; $varnames I get something like: Some Data 1, Some data 2, Some Data 3, etc.

But that is where I am stuck! How can i now take all that data and loop through it to insert everything into the table that will look similar to my HTML example that I mention in my first post?
 
I don't know what you are missing,
but there is no hidden field in your page:

No hidden field, no information passed to the next page unless you use session variables.

It would be a good idea to post the code that you use to generate the initial page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top