how to insert from data into MYSQL database php

0
2778

Overview

in this tutorial we learn how to insert query of mysql works
and for demonstration we will insert Login form username and password into database as user login history.

action page nextpage.php snippet code :

$usernameVal=$_REQUEST["username"];
$passwordVAl=$_REQUEST["password"];


$servername = "localhost";
$username = "root";
$password = "";
$dbname = "userstest_db";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else//Connection established
{
$sql= "insert into loginlogs (`username`, `password`) 
VALUE('$usernameVal','$passwordVAl') ";
$result=$conn->query($sql);//it will give true if inserted else false
    if($result==true)
        echo "user logs inserted successfully";
    else
        echo "user logs insertion error";
}

Summary

how insert query works in mysql php and for demonstration we will insert Login form username and password into database as user login history logs.