Skip to content

Instantly share code, notes, and snippets.

@ElectApp
Last active March 18, 2019 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElectApp/b07b201bf5564fe27795f3a8f6818f2c to your computer and use it in GitHub Desktop.
Save ElectApp/b07b201bf5564fe27795f3a8f6818f2c to your computer and use it in GitHub Desktop.
<?php
//Thank: https://www.w3schools.com/php/php_mysql_insert.asp
$servername = "localhost"; //ใช้ localhost กรณี server อยู่บน online
$username = "พิมพ์ที่นี่"; //username ของ DirectAdmin/phpMyAdmin
$password = "พิมพ์ที่นี่"; //password ของ DirectAdmin/phpMyAdmin
$dbname = "test"; //ชื่อ database
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Get data from user
$name = $_POST['name'];
$pass = $_POST['password'];
if(empty($name) || empty($pass)){
die("Please enter name and password!");
}
//Add data to table
$sql = "INSERT INTO user_login_test (id, name, password) VALUES (NULL, '$name', '$pass')";
//Check result
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment