Moving information from an HTML form into a database is a two-step design process. First, create an entry HTML form capable of passing information to a secondary file. Next, create a Hypertext Preprocessor [PHP] file to accept the data and insert it into the database.
HTML is only capable of instructing a browser on the method of presenting information. The transactions needed to store information in the database require Structured Query Language [SQL] commands placed inside a PHP script.
HTML
Create a Form on the Appropriate Page
Create a form on the appropriate page including the “action” and “method” attributes in the form definition tag as follows:
The “action” attribute tells the form to send the data to a script named “info.php,” and “method” describes the type of action to be performed once the information is passed to the script.
Define Input Fields
Define the input fields along with the data types to be passed to the database. For example:
Username: Email:
Together, these tags pass two text strings named “username” and “email” to the PHP script.
Create Submit Button
Provide the user with a way to initiate the transaction with the tag:
This displays a “submit” button at the bottom of the form that triggers the database transaction.
PHP
Create a File
Create a file named “info.php.” Any file name can be used as long as it matches the name specified by the form's “action” attribute and ends with the .php extension.
Connect to Database
Open the PHP script and connect to the database with the statements:
In the first line, the SQL statement used to insert the information in the database table “table_name” is passed to the variable “$user_info.” The following “if” statement verifies the connection to the proper table, inserts the data contained in “$user_info into the table. If the transaction can't be completed, an error message is generated and the connection is closed. The “echo” statement appears only if the information is successfully saved. Finally, calling “mysql_close” closes the database connection.
Tip
You must create the database and tables before passing data to them. The table's field names must match the names of the variables passed by the “$_POST[xxxxx]” global variables.
I am building a webpage that inlcude entering data into a databse. I am successfully connecting to my database, and my insert query is working as far as it is adding rows into the database, but the form data is not getting pass across so the rows are being created [ I have seen them in phpmyadmin] but the data is empty.
I have two pages. One for displaying the form, and one that receive sthe form data and runs the sql query.
This is the data for the form webpage
Venue:
Date:
Time:
Postcode:
This is the code that I am using for entering the data. I have not included the connection code for the database as I am not having a problem with this.
$venue = $_POST['venue'];
$date = $_POST['date'];
$time = $_POST['time'];
$postcode = $_POST['postcode'];
$query = "INSERT into `event`[`eventVenue`, `eventDate`, `eventTime`,
`EventPostCode`] VALUES [ '$venue', '$date','$time', '$postcode' ]";
mysqli_query[$dbconn, $query];
Db Connection:
$host="50.62.209.87"; // Host name
$username="************"; // Mysql username
$password="********"; // Mysql password
$db_name="extras"; // Database name
// Connect to server and select databse.
$dbconn = mysqli_connect[$host, $username, $password]or die["cannot connect"];
mysqli_select_db[$dbconn, $db_name]or die["cannot select DB"];