Horje
How to insert data into Mysal Database using html form PHP

Following is the best tutorial to insert data into Mysql Database using HTML Form PHP


Step-1: Login to Cpanel

Login to your Cpanel using https://yourdomain.com:2083/

Output should be:

Step -2: Find Database

  1. Find Database from Cpanel Options.
  2. Then, Click on Manage My Databases

Output should be:

Step -3: Create Database

  1. Scroll Down and find New Database
  2. Insert Database Name and Click on Create Database Button

Output should be:

Step -4: Create Mysql User and Password

  1. Go Back Manage My Databses Option.
  2. Scroll to  Add New User
  3. Insert Username and Password.
  4. Click to Create User Button.

Output should be:

Step -5: Add user to databse

  1. Now, Scroll down to Add User To Database
  2. Select, User and Database
  3. and Click to Add Button

Output should be:

Step -6: Select ALL PRIVILEGES

  1. Select the privileges you want to grant the user,.
  2. or click on ALL PRIVILEGES to grant the user all permissions to the database.
  3. Click on Make Change Button

Output should be:

Step -7: Go to phpMyadmin

  1. Go back Cpanel.
  2. Find Databases
  3. Click phpMyadmin

Output should be:

Step -8: Select a Database

  1. Select Database from Leftside menu

Output should be:

Step -9: Create new table

  1. Put Table Name: school
  2. Put Number of Column: 2
  3. Click to Create Button

Output should be:

Step -10: Create Column

  1. Put Name of Column: id and name
  2. Select type: for id: INT and for name: VARCHAR and for value: 20
  3. Then, Click on Save Button

Output should be:

Step -11: Go to Filemanager

  1. Now, Go back Cpanel
  2. Scroll to Files
  3. Click on Filemanager to open it.

Output should be:

Step -12: Double Click on public_html

Now, double click on public_html from filemanager

Output should be:

Step -13: Create index.php file

Now, Click on File from top MenNow a Box will appear.

  1. Put New File Name: index.php
  2. and Click on Create New File Button

index.php file has created to your server.

Output should be:

Step -14: Open index.php file

  1. Select index.php file to Open this Page.
  2. Click right button of your Mouse.

  1. Now, Click on Edit
  2. Then, Copy Following Codes and Paste There into index.php file.
  3. Now, Click Save Changes Button top Right Side.
index.php
Example: PHP
<!DOCTYPE html>
<html lang="en">
    


   <head>
      <title>GFG- Store Data</title>
   </head>
   <body>
      <center>
         <h1>Storing Form data in Database</h1>
         <form action="" method="post">
            
<p>
               <label for="firstName">Enter ID:</label>
               <input type="text" name="id" id="id">
            </p>

            
<p>
               <label for="lastName">Enter Name:</label>
               <input type="text" name="name" id="name">
            </p>

            


            <input type="submit" value="Submit">
         </form>
      </center>
   </body>
</html>

</br>
<center>
  <?php
        
        // Taking all 5 values from the form data(input)
        $id =  $_REQUEST['id'];
        $name = $_REQUEST['name'];
  
if (!empty($name)) {
        
$servername = "localhost";
$username = "oleforce_test";
$password = "7B+.6LI)M?+j";
$dbname = "oleforce_test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO school (id, name)
VALUES ('$id', '$name')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
        
}
        ?>
        
</center>  
<style>
.responsive {
  width: 100%;
  height: auto;
}  

input[type=text], select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    resize: vertical;
}

input[type=password], select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    resize: vertical;
}

label {
    padding: 12px 12px 12px 0;
    display: inline-block;
}

input[type=submit] {
    background-color: #66afe9;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    float: center;
}

button[type=submit]:hover {
    background-color: #66afe9;
}    
</style>
</body></html>

Output should be:

Step -15: Now, Run index.php

  1. Go to Browser
  2. Run https://yoursite.com/index.php
  3. Then, Input Id and Name and Click on Submit button.

Data Submitted to Your Database.

See the output of Database saved to Your Database id and name.

Output should be:





mysqli data insert

Related Articles
How to insert data into Mysal Database using html form PHP Mysqli Insert Tutorial


Read Full:
Mysqli Insert Tutorial
Type:
Develop
Category:
Web Tutorial
Sub Category:
Mysqli Insert Tutorial
Uploaded by:
Admin
Views:
168