How Do I Make A Web Form That Saves Information To A Database?

2009-12-21 at 09:26 am hugege

So I want to make a web form (on a website) that users can fill out with some simple information. Once they fill it out, I want the information to be saved to a MySQL database (or something similar). I also want to be able to call this information back on a seperate web page. How would I go about doing this? I’m not big on programming, so it would be really helpful for me if you could link me to a tool I can use.

4 Responses to “How Do I Make A Web Form That Saves Information To A Database?”

  1. Angela Q

    Without knowing any php, I doubt you can do that. You should hire someone to set it up for you. ∠°)

  2. aznsrdab

    i think you can do that with a free program called OutWit Hub:

  3. Martin R

    Take a look at
    I will be happy to help you set this up.

  4. natlang

    You can use PHP for this. In your HTML form element, you set the attributes method=”post” action=”url_of_the_php_file”. Make sure to give a unique name to each input field in the form.
    Then when the user clicks Submit, the browser will send the data from the form to the PHP script. All of the form data is stored in a special PHP variable called $_POST.
    Before you can send data to the database, the script needs to connect to it. This is done with the mysql_connect() function. For example, $db = mysql_connect(“localhost”, “yourDbUserName”, “yourDbPassword”); The $db variable contains a “link” to the database. You don’t need it for much because PHP automatically uses the most recent link if you don’t tell it which one to use, but there it is in case you need it.
    You can access the data in $_POST with syntax like $varName = $_POST[“formFieldName”]. However, I strongly recommend using
    $varName = mysql_real_escape_string( $_POST[“formFieldName”]);
    for all of your data, as it will help protect your site from being hacked! (Yes, it really will happen.) Escaping the data like this prevents malicious users from injecting extra commands to your database.
    Once you have a link to the database and your data is all stored in variables, you send a SQL command to INSERT, UPDATE, SELECT, etc. It sounds like you want to insert, so that would go something like this:
    $sql = “INSERT INTO ‘yourTable’ (‘colName1’, ‘colName2’, etc.) VALUES (‘$yourVar1’, ‘$yourVar2’, etc.)”;
    if (!mysql_query($sql)) die “Error!”;
    I suggest reading through the two links below before digging in. They cover a lot more about error handling and security, as well as how to get the data back out of the database. There is a lot to learn, but you don’t need to master everything in order to make use of it. Just remember to escape those queries (and all browser-submitted data for that matter). 🙂

Leave a Reply