Build a simple web application
let's build a simple web application that accepts user input and saves it to a MySQL database. Here's the step-by-step process:
Create a database and table in MySQL: First, you need to create a database and table in MySQL. You can use any MySQL management tool like phpMyAdmin or MySQL Workbench for this. Let's assume we have created a database called "myapp" and a table called "users" with three columns - "id" (auto-increment), "name" (varchar) and "email" (varchar).
Create a HTML form to accept user input: Create a HTML form with two input fields - "name" and "email" - and a submit button. You can use the following code to create the form:
HTML form (index.html):
Create a PHP script to process the form data and save it to the database: Create a new PHP file called "process.php" and write the code to connect to the database and insert the user data into the "users" table. You can use the following code:
PHP process file (process.php):
Note: Replace mydatabase
, mytable
, and database credentials with your own values. Also, make sure to save both files in the same directory on your XAMPP server.
Last updated