/    Sign up×
Community /Pin to ProfileBookmark

Submitting a form and getting it to look like you want?

Hello,

I am making a program using html to help a company standardize its procedures. I have made a form in html that is made up of 9 tables. The user enters the data in these tables and then clicks the submit button.

Now what I want to do, is have the entered data appear in one big table on the same ‘web’ page. Basically everything entered in the small tables is then transferred to one big table after clicking submit… if that makes sense.

How do I do that? Do I have to mess with ‘action’ in form method or design another html program?

Thanks,
Michael

to post a comment
HTML

7 Comments(s)

Copy linkTweet thisAlerts:
@ryanbutlerOct 05.2008 — You'll need to set the action on the form tag to the same file that you use to create the original form and make sure the method is post. You have a couple different strategies to display all the data into one table, which depends on what server side language you're using. If it's PHP, you could simply check the post collection to see if a submission has taken place, and if so, build the table through code.

[code=php]<?php

if (isset($_POST['submit'])){

echo "<table>";
echo "<tr>";
echo "<td>" . $_POST['field_1'] . "</td>";
echo "</tr>";

}
else{
echo "<p>No submission has taken place</p>";
?>
}[/code]


Which for all intensive purposed is somewhat annoying, but easy enough. You just need to grab each value of the form field through the $_POST collection.

Or you could store the entries in a database table, and then query for that using SQL and append a query string asking for the unique ID. The first method I described would be the easiest, though if you need that information for later use, a database would be the way to go.
Copy linkTweet thisAlerts:
@Michael84authorOct 12.2008 — Hi,

I am not sure how you set the action on the form tag to the same file that I used to create the original form. Is it in the apostrophes after Action?:

<html>

<FORM METHOD="POST" ACTION=" ">

<head>

How do I confirm that I am using php? Also the point of this program is to document the data in a table (i.e. You enter data in a big table that has too many rows then click submit and it is supposed to appear in a cleaner table that can be saved) for future reference so I think the database option is the way forward but I am unsure what SQl is and query string?

I am sorry for these simple questions but it is the first time I write code and the first time I am using html...

Thanks,

Michael
Copy linkTweet thisAlerts:
@ryanbutlerOct 13.2008 — For starters, you'll want to set the action of the form tag to a result page, so see the results of what has been submitted.

<form action="myresults.php">

You find out what's available by asking your system admin. Just ask what server-side technologies/languages are available.

I'll help more when you come back with that.
Copy linkTweet thisAlerts:
@Michael84authorOct 15.2008 — Hi,

Thanks a lot for the help. Just to be clear, what I outlined as my task is all my project encompasses and no more. So displaying this user entered information on a separate page in table form is all that is required for this project.

I spoke to my project tutor and he said that I may have to learn one of these languages i.e. SQL or PHP. I have come to terms that I will have to do this but was wondering which one you would recommend for someone who has never programmed before.

When researching I found a lot of sample code on how to create an html form but no information or sample code on the form tag file e.g. myresults.php from <form action="myresults.php">.

Any help would be appreciated.

Thanks,

Michael
Copy linkTweet thisAlerts:
@ryanbutlerOct 16.2008 — When I stated I would help further with more information, I was simply stating the fact that in the past I've coded a minimal solution and found out that it wasn't needed, so I wasted my time, and I hate that.

I would say PHP is you're best best. .NET and it's technologies take a while to sink in. So, you're faced with PHP, a MySQL database, and learning Structured Query Language (SQL) if you want to keep a record of the results.

So you have a form, we'll say first and last name, email and comments. So, you'll create a PHP page that will insert the results into your database table. Your database table will need columns for each of your input fields (first and last name).

So on the form that collects the information, inside the opening form tag you'll do this:

[CODE]<form method="post" action="result.php">[/CODE]

Inside the original form, you'll have to have a PHP file, called form.php. Before the DOCTYPE, I'd do this:

[code=php]<?php

if(isset($_POST['submit'])){

//grab the values from the post collection

$FirstName=$_POST['firstname'];
$LastName=$_POST['lastname'];
$Comments=$_POST['comments'];

//insert the values into the database table

$sql="INSERT INTO MyTable (FName,LName,Comments)VALUES('$FirstName', '$LastName', '$Comments')";

//check to see if the query is successful and move to result page if it is

if(@mysql_query($sql){
Location("http://www.somedomain.com/result.php");
}

else{
echo "An error has occurred";
}

?>[/code]



Inside result, you'll have to do this:

[code=php]<?php

//create connection to the database server
$dbconn=mysql_connect("username", "password") or die("Can't connect to the database") . mysql_error());

//select the database to use
$db=mysql_select_db("yourdatabase");

//create sql query to extract values
$sql="SELECT * FROM My_Table";

//assign the results of $sql to associative array
$result=mysql_result($sql);

//loop through the result set
while($row=mysql_fetch_array($result)){

//grab each insert value and place in row variable

$FirstName=$row["FName"];
$LastName=$row["LName"];
$Email=$row["Email"];

//build the output table

echo "<table>";
echo "<tr>";
echo "<td>". $FirstName . "</td>";
echo "<td>". $LastName . "</td>";
echo "<td>". $EmailName . "</td>";


}


?>[/code]


I coded this fairly quickly, so I might be off in a few places syntactically, but the solution is solid. I didn't add validation which you'll probably want once you get this part working.

Now I'm reminded why I like .NET & C# with ASP.NET so much better. I could've coded that solution about twice as quick with that platform. Let me know if you have questions.
Copy linkTweet thisAlerts:
@Michael84authorOct 19.2008 — Hi,

I am having problems implementing the code written above. What do you mean by having a php file called form.php inside the original form? Do you mean putting the code you suggested before the doctype or put it in a separate file called form.php that I create in Notepad?

I have been reading some textbooks and it says I need to create an SQL table, Do you know how to do that and is it required?

I would just like to clarify that this is not an internet application and will be used internally by only one computer at a time.

If it is not an online form per se do I need to have a database server? How do I get one?

After the user has filled in the table and clicks submit, do I need an intermediate stage that processes the data and then puts it into a new table?

Does the action result.php file have to be in the same directory as my original form file? This is because I am only dealing with files that I execute from my computer and nothing to do with the internet.


Again sorry for these simple questions,

Thanks,

Michael
Copy linkTweet thisAlerts:
@ryanbutlerOct 19.2008 — 
I am having problems implementing the code written above. What do you mean by having a php file called form.php inside the original form?

Do you mean putting the code you suggested before the doctype or put it in a separate file called form.php that I create in Notepad?
[/quote]


I mean that the original file that contains the fields that you want to collect the information needs to be a PHP file with a PHP extension, otherwise, you can't insert or do any programming logic inside the file. Put the code for the insertion of the records into the database table above the DOCTYPE in the file named form.php


I have been reading some textbooks and it says I need to create an SQL table, Do you know how to do that and is it required?
[/quote]


Yes, I know how to do that, but it depends on your host and what tools they provide. Generally it's either Php My Admin or SQL Server Management Studio for MS SQL server. It's required if you want to keep a record of all submissions for future reference, otherwise, it's not. I think Web Reference.com, has an article about how do to do that, it's for the most part, cake.


I would just like to clarify that this is not an internet application and will be used internally by only one computer at a time.

If it is not an online form per se do I need to have a database server? How do I get one?
[/quote]


There would be no other way that I could see that a user could fill out the information, press a submit button and have their information displayed in its entirety unless you did a Word macro (not even sure that would work), which would mean interfacing with the API of word, which is a whole another ball game. So are you viewing this as more of a web page that exists on your company's intranet? If you have a web server with intranet capabilities, you probably have a database server. Perhaps you can ask a system administrator? Maybe a better question from me is: what exactly is your Information System setup where this will be residing? You don't have to provide specifics for security reasons on a public forum, just provide generics if it helps explain the setup and this question, as you have me a bit confused.


After the user has filled in the table and clicks submit, do I need an intermediate stage that processes the data and then puts it into a new table?
[/quote]


Once the user filled in the initial table and clicks submit, the script in form.php will insert the data into your database table, and then a subsequent file, result.php will query the database table allowing you to control what information is put into the one big table that shows users what they entered.


Does the action result.php file have to be in the same directory as my original form file? This is because I am only dealing with files that I execute from my computer and nothing to do with the internet.
[/quote]


You mean the file result.php, no it doesn't have to be in the same directory as the original form file, because the data is stored in the database table.

Again sorry for these simple questions[/quote]

No problem...I remember the early days myself ?
×

Success!

Help @Michael84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...