Capturing form input

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I will try to be short and to the point.(good Luck)  I have a form
written in HTML. I have a Mysql database. I am using a linux server
and I would like to use php to write the following code:

After the user inputs their name, address, email, phone, etc. in my
html form. They will hit the submit button. I need for the information
they entered to go into my database.

I have looked now for about 12 hours and haven't been able to find an
answer. I know I must be missing something since I've been to the w3
site, codewalkers, phpfreaks,, and many more.

If there is an easier way of doing this I would love to hear it.

If somene could point me in the right direction I could stop banging
my head and pulling my hair.

THANK YOU in advance for your advice.


Re: Capturing form input

Quoted text here. Click to load it

Its going to be more work and its going to take you some time to learn it.

1. You'll need a web server like apache, php, and an sql like mysql. They  
are all free and easy to install with many online tutorials.

2. Get apache and php up and running with appropriate modules and  
extensions. This should actually be part of 1.

3. Create some simple php scripts for testing. Again, there are online  
tutorials for this.

4. Now try to get some mysql code working. Its actually very easy but you'll  
need to learn the sql language which is also easy but at first might seem  

5. Now work with php and forms. This is again very easy and there are many  
online tutorials about how to do it.

6. Put everything you've learned together to do what you want.

Each step is actually very easy although they can be time consuming if you  
get in trouble.  Its best you learn how to do everything because it builds  
character ;) Actually you'll be glad you learned it because its not  
hard(Although it might seem that way) and you'll be in a much better  
position to do things you want and how you want.

Since all the tools you need are free the only thing you have to pay is  
time. Again, its not hard but it will take time for you to learn all the  
little things. Give yourself a few months and you'll have it down. If your  
diligent you could probably get enough done in a month or so.


Re: Capturing form input

Cigar2011 wrote:
Quoted text here. Click to load it

The data from the form with go to the script named in the action  
parameter of the form tag.

in that script the data will be in the $_POST array.


<form action="contact_manage.php" method="post">
<input type="text" name="fname" size="20" />
<input type="text" name="lname" size="20"/>                
<input type="submit">

then in the script, "contact_manage.php"

$first_name = $_POST['fname'];
$last_name  = $_POST['lname'];

But, don't even think about putting user supplied data directly  
into the database.  Bad things can happen.


Re: Capturing form input

Quoted text here. Click to load it

I came accross this little script today that should save a lot of the
effort. It creates the form for you and submits the data to your


got to sort the security bit though

Re: Capturing form input

In our last episode,  
the lovely and talented Cigar2011  
broadcast on comp.lang.php:

Quoted text here. Click to load it

What answer?  It seems you want the whole thing done for you, like it
is homework.  What is the problem you are having?  Are you unable
to get the data to your form handler?  Funny because although this
has a few more variables, it is exactly like "A simple tutorial,"
which is in section I of the PHP Manual.  Yes some manuals bury an
introductory lesson like that way down after all the installation and
configuration stuff, by PHP puts it right on top.  Did you spent 12 hours
without finding the very first thing in the Manual?  Do you even have the

Is your problem with MySQL?  If you have the data, can you enter it from the
mysql prompt (creating the table if you need to)?  If you can't get the data
into your database from a mysql client prompt, you have no hope of getting
it in with PHP because you have to be able to write valid MySQL commands to
use PHP to send those commands to MySQL.  Is the problem that you don't know

If you are past that, what is the problem?   Can you connect to the MySQL
server?  Can you connect to your MySQL database or not?  Can you select a
table?  Where is the problem? Which PHP mysql_* functions have you tried?
The manual has detailed examples of most of them.  Look them up in the
function index at the bottom of the manual.   In 12 hours you must have
found a few of them.  What did you try?  What went wrong?

Quoted text here. Click to load it

People get paid for doing this stuff.  Here are some hints if you hope
to get paid for it --- or at least hope to avoid having to pay someone
else to do it for you:

1.  Use a text browser to get things to work.  Lynx is one, there are
others.  Don't worry about making pretty-pretty until you have valid markup
that works.  This is a heck of a lot easier, especially if you tend to get
distracted by shiney objects in GUIs.

2.  If you are stuck, divide the problem into little parts.  In your case,
a way of dividing the parts would be a) make the form, b) get (actually
probably POST --- thats a little joke) the form data to a handler, c)
figure out how the handler will know the data is valid, d) connect to the
database, e) insert the data, and (until you are certain you have it right,
at least) f) figure out how to verify that what you did to the database was
what you intended to do.

3)  When you are stuck, try things out by hand.  Use PHP CLI to see if you
are getting the markup you think you are getting and pipe it through a
validator.  Use the MySQL command-line client (conveniently called mysql on
many systems) to get your MySQL commands right --- because if you cannot
talk intelligently to MySQL from mysql, there is no hope you can talk
intelligently to MySQL through PHP.

4)  When something works, save it --- save it some place you won't mess with
it.  You can copy it and fill in the blanks to perform a task that is just a
little different.  When you are copying something from your saved snippets
for the third or fourth time, it time to consider making a function of it.

5)  When you are read to make pretty-pretty, use stylesheets as much as
possible.  If you use CSS, learn to use context so you don't have to have
a class or id attribute on every little element.

Quoted text here. Click to load it

Lars Eighner     < <
                         Countdown: 583 days to go.
An amazing thing about Christians:  people who doubt being related to monkeys,
but are certain they belong to the same species as Paris Hilton or Karl Rove.

Site Timeline