html form to php script to db HELP !

Problems with the Windows version of XAMPP, questions, comments, and anything related.

html form to php script to db HELP !

Postby pyro » 08. February 2005 06:15

Hi Guys

Yet another problem !!!

I have a form on a web page it can be seen here

I have looked for a tutorial to show me how to write a script that when the form sends this info to a php script this data will then be stored on a database.

I understand I have to post the form to a script, but I cannot find and info on how to do this, Has anyone got a old script hanging around they could send me that I can alter some info in and it would work?

I am stuck on this one and any help would be good


Posts: 11
Joined: 07. February 2005 03:03

Postby Wiedmann » 08. February 2005 10:58

AF Moderator
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Simple Script

Postby webmosher » 08. February 2005 15:45

Well... here is something very simple, but hopefully will illustrate the point. It contains both the form and the code:

Save code as form.php
Code: Select all
// Check if we just started counting
if (isset ($HTTP_POST_VARS['count']) && $HTTP_POST_VARS['count'] != '')  {
$count = $HTTP_POST_VARS['count'];
} else {
$count = 0;
// Lets count (increment by one).
$count ++;
<form action="form.php" method="post">
Learning to count: <input type="text" name="count" value="<?php echo $count; ?>"/>
<input type="submit" value="Count"/>

From an experienced coding perspective, this little snippet has alot of things wrong with it. It does work fine (yes, its tested). Learning to code in PHP is often an iterative process. You can worry about proper semantic coding and methodology as you gain experience.

Here is a small explaination of some of the more important details. The top portion of the segment is a piece of code that intercepts the input from the form and does some work on it. In this case, we are taking data from the form field "count" and adding 1 to it. We then set this variable back into our form. The PHP global system variable HTTP_POST_VARS contains all the data that was sent to the web server in a form with the POST method. If you use the GET method, your variables are stored in HTTP_GET_VARS. PHP5 changed this a bit, but still uses these names for compatibility. You'll note that I verify that the post data has something in it before I do anything with it. This isn't as important in PHP, but validating input is always an important idea to start with early.

The form itself is pretty simple. The form tag has at least two basic elements. The "action" is the name of the script you are posting to. In this case, its ourself, "form.php". You can also provide a "method" of either GET or POST. Forms always default to GET, so if you leave out the method, you will not get any POST data in PHP. GET method will encode the form options into the URL itself, so you get something like this:

Alot of coders don't like exposing their variables this way. POST allows all that data to be encoded into the HTTP header that the browser sends to the server. Most users don't go looking for this info, but if you're serious about web development, the HTTP header can quickly become your friend. One other advantage of POST is that it has no real size limitation (other than what the server forces), so if you have large amounts of text to push around in forms, you have to use post. Otherwise, your data will get truncated or behave badly

Anyhow, hope this helps...
Posts: 7
Joined: 08. February 2005 15:01

php form

Postby pyro » 08. February 2005 18:26

Hi All

Thanks for your help, but i am still lost...! I was wondering if you could help me out with the following

If you go here you will see a html page with a form on it called " form 2 " you will also see 10 dropdown boxes called "target1 through to target10 "

I am trying to get the scores entered here to be submitted to a PHP script which in turn sends the info to a MySQL database

Would you be so kind as to start the php script for me, I realy am struggling with this and would buy you a drink or drinks for your trouble ! ( cant be many though as I am a Poor old student !)

I would not ask you if I did not need to , If you could get it to work for me with say 3 of the target dropdowns included I will add the rest as long as it is not to hard for me to understand

I hope you can help me out, as it is people like you make learning diferent thing a little easyer. I am dedicated enough to want to learn this but just need a point in the right direction

Please advise

Posts: 11
Joined: 07. February 2005 03:03

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 39 guests