How to Create a XAMPP MySQL Database
How to Create a XAMPP MySQL Database
Introduction
XAMPP is an acronym that stands for Cross-Platform (X), Apache (A), MariaDB (M), PHP (P), and Perl (P). It was created by Apache buddies. XAMPP Server is an open-source local WebServer that runs scripting languages (PHP, PERL). It comes with Apache and MySQL, as well as FileZilla, Mercury, and Tomcat.
Using XAMPP Server, I will demonstrate how to construct a database and insert data into it.
Requirements
- XAMPP Server
- Brackets (IDE)
- A little bit of Web development knowledge
The steps that must be taken are outlined below.
Follow my steps carefully to establish a database and insert data into the database using XAMPP Server, and I've included the source code below.
Step 1
Download the latest version of Windows XAMPP Server from the Webpage given below.
Download link: https://www.apachefriends.org/download.html
Step 2
Select your language and click Next.
Step 3
Choose your destination folder.
Step 4
Select all the Services, followed by clicking Install.
Step 5
This is XAMPP Control panel. Start Apache and MySQL Server. Now, provide permission for Apache and MySQL accesses the firewall.
Step 6
Open your Browser, followed by typing http://localhost or http://127.0.0.1. Afterwards, you will see XAMPP community page.
Step 7
Open the XAMPP Control Panel, followed by clicking MySQL admin.
Step 8
Create the new database and click New.
Step 9
Put the database name as whatever you want. Here, the database name tutorial is given. Click Ceate.
Step 10
Go to SQL query tab, and copy and paste the query given below. Click Go. Afterward, your table (my table name: person) creates successfully.
MySQL query
- CREATE TABLE `person` (
- `Id` int(11) NOT NULL,
- `Name` varchar(20) NOT NULL,
- `Email` varchar(25) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Step 11
Put your Webpage files into the destination folder. The default folder is c:/xampp/htdocs.
Step 12
Open the bracket (IDE) and create the index.html file. Copy the code given below and paste it into index.html.
Index.html
- <!DOCTYPE html>
- <html>
- <head>
- <title>
- Xampp Tutorial
- </title>
- <style>
- h1{
- color: rebeccapurple;
- font-family: fantasy;
- font-style: italic;
- }
- </style>
- </head>
- <body>
- <h1>Xampp Tutorial</h1>
- <hr>
- <form action="insert.php" method="post">
- <fieldset>
- <legend>enter the details below</legend>
- <label>Name</label><br><br>
- <input type="text" placeholder="ex:john" name="Name">
- <br><br>
- <label>Email</label><br><br>
- <input type="email" placeholder="hello@gmail.com" name="Email" >
- <br><br>
- <input type="submit" value="insert">
- </fieldset>
- </form>
- </body>
- </html>
Step 13
Create the insert.php file. Copy the code given below and paste it into insert.php.
insert.php
- <?php
- $con = mysqli_connect('127.0.0.1','root','');
- if(!$con)
- {
- echo 'not connect to the server';
- }
- if(!mysqli_select_db($con,'tutorial'))
- {
- echo 'database not selected';
- }
- $Name = $_POST['Name'];
- $Email = $_POST['Email'];
- $sql = "INSERT INTO person (Name,Email) VALUES ('$Name','$Email')";
- if(!mysqli_query($con,$sql))
- {
- echo 'Not inserted';
- }
- else
- {
- echo 'Data Inserted';
- }
- header("refresh:3; url=index.html")
- ?>
Step 14
Run index.html. Give the name and an E-mail Id.
Step 15
The data is inserted. Afterward, go to the database and check it.
Step 16
Go to the tutorial database. Open the person table. name and an email id were inserted successfully.
Output
Our message is now included in a dynamic Webpage that has been developed and performed. In my next essay, I'll go over XAMPP, FileZilla, and GitHub lessons in further detail.
Post a Comment