0

So I am trying to fill out customer info, then send the customer info into the sql database table. I already have my database made so I know the right values are going into it. Just dont know how to get it in. Thanks I have posted code for the customer screen.

<html>
<head>
    <title>Customer Info</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        table, td
        {
            border: 5px blue;
        }
    </style>
    <script type="text/javascript" src=validator.js></script>
    <link rel="previous" href="index.html">
</head>
<body>
    <h1 style="text-align:center;color:steelblue">
        Customer Info
    </h1>

    <h5 id="errorMessage" style="text-align:center;color:red"></h5>

    <form action=customerinfo.html method="POST" onsubmit="return validateCustomerForm(this)">
        <table style="margin-right:auto;margin-left:auto">
            <tr>
                <td style="text-align:right">First Name:</td>
                <td><input type="text" name="firstname" size="30"/></td>
            </tr>
            <tr>
                <td style="text-align:right">Last Name:</td>
                <td><input type="text" name="lastname" size="30"/></td>
            </tr>
            <tr>
                <td style="text-align:right">Address:</td>
                <td><input type="text" name="address" size="50"/></td>
            </tr>
            <tr>
                <td style="text-align:right">City:</td>
                <td><input type="text" name="city" size="30"/></td>
            </tr>
            <tr>
                <td style="text-align:right">Province</td>                    
                <td>
                    <select name="provinces">
                        <option>[Select Province]</option>
                        <option>AB</option>
                        <option>BC</option>
                        <option>MB</option>
                        <option>NB</option>
                        <option>NL</option>
                        <option>NS</option>
                        <option>NT</option>
                        <option>NU</option>
                        <option>ON</option>
                        <option>PE</option>
                        <option>QC</option>
                        <option>SK</option>
                        <option>YT</option>            
                    </select>
                </td>
            </tr>
            <tr>
                <td style="text-align:right">Postal Code:</td>
                <td><input type="text" name="postalcode" size="7"/></td>
            </tr>
            <tr>
                <td style="text-align:right">Telephone#:</td>
                <td><input type="text" name="telephone#" size="12"/></td>
            </tr>
            <tr>
                <td colspan='2' style='text-align:center'>
                    <input type='Submit' value='Submit'/>
                </td>
            </tr>
        </table>
    </form>       
</body>

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Connecting directly to an SQL server via JS is not very secure. You should use something like PHP on the server to handle AJAX requests. However, there is already a post like this, [here](http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript) – vulpcod3z Nov 19 '14 at 14:26

1 Answers1

2

You need a server-side language like PHP. So you have to read about PHP, and how you can connect PHP with your database, e.g MySQL.

You also need to change your HTML form action to the PHP file, e.g

<form action="yourPHPFile.php" method="POST" onsubmit="return validateCustomerForm(this)">

A simple example where you can start with:

<?php
$firstname = $_POST[firstname];
$lastname = $_POST[lastname];
.
.
// commands to open a connection to your database
// commands to insert into your database (query)
// close the database connection
.
.
.
?>

Notes:

  1. $firstname is a variable and in PHP the variables must begin with $ symbol
  2. $_POST is used to get the information provided by the user via the HTML file you gave. Is $_POST because you use as method the POST in your HTML form, there is another one way to do that and is with the GET method.

Below, are some introduction links where you can start:

For connection

For insert data to your table

Just go through the MySQL Database section at the website provided.

Dr. Programmer
  • 368
  • 1
  • 7
  • 19