Header Ads

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

  1. CREATE TABLE `person` (  
  2.   `Id` int(11) NOT NULL,  
  3.   `Namevarchar(20) NOT NULL,  
  4.   `Email` varchar(25) NOT NULL  
  5. ) 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

  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <title>  
  5.             Xampp Tutorial  
  6.         </title>  
  7.       <style>  
  8.           h1{  
  9.               color: rebeccapurple;  
  10.               font-family: fantasy;  
  11.               font-style: italic;  
  12.           }  
  13.         </style>  
  14. </head>  
  15. <body>  
  16.     <h1>Xampp Tutorial</h1>  
  17.     <hr>  
  18.     <form action="insert.php" method="post">  
  19.             <fieldset>  
  20.                 <legend>enter the details below</legend>  
  21.                 <label>Name</label><br><br>  
  22.                 <input type="text" placeholder="ex:john" name="Name">  
  23.                 <br><br>  
  24.                   
  25.                 <label>Email</label><br><br>  
  26.                 <input type="email" placeholder="hello@gmail.com" name="Email" >  
  27.                 <br><br>  
  28.                 <input type="submit" value="insert">  
  29.             </fieldset>  
  30.         </form>  
  31.     </body>  
  32. </html>  



Step 13

Create the insert.php file. Copy the code given below and paste it into insert.php.

insert.php

 
  1. <?php  
  2.   
  3. $con = mysqli_connect('127.0.0.1','root','');  
  4.   
  5. if(!$con)  
  6. {  
  7.     echo 'not connect to the server';  
  8. }  
  9. if(!mysqli_select_db($con,'tutorial'))  
  10. {  
  11.     echo 'database not selected';  
  12. }  
  13.   
  14. $Name = $_POST['Name'];  
  15. $Email = $_POST['Email'];   
  16.   
  17. $sql = "INSERT INTO person (Name,Email) VALUES ('$Name','$Email')";  
  18.   
  19. if(!mysqli_query($con,$sql))  
  20. {  
  21.     echo 'Not inserted';  
  22. }  
  23. else  
  24. {  
  25.     echo 'Data Inserted';  
  26. }  
  27. header("refresh:3; url=index.html")  
  28. ?>  



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.

No comments

Powered by Blogger.