![]() |
Following is the best tutorial to insert data into Mysql Database using HTML Form PHP |
Login to your Cpanel using https://yourdomain.com:2083/
Now, double click on public_html from filemanager
Now, Click on File from top MenNow a Box will appear.
index.php file has created to your server.
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>
Data Submitted to Your Database.
See the output of Database saved to Your Database id and name.
mysqli data insert |
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 |