Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Created February 6, 2016 04:39
Show Gist options
  • Save VMuliadi/31ea45087d95a613cefc to your computer and use it in GitHub Desktop.
Save VMuliadi/31ea45087d95a613cefc to your computer and use it in GitHub Desktop.
<?php
// define the mysql settings
define("DB_SERVER", "localhost");
define("DB_USERNAME","username");
define("DB_PASSWORD", "password");
define("DB_NAME", "database");
// setting MySQL table and configuration
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME) or die ("Cannot connect");
// read input from user
$username = $_POST["username"];
$password = $_POST["password"];
if(isset($_POST["login"])) {
if (empty($_POST["username"]) || empty($_POST["password"])) {
echo "Fill the username and the password text field";
} else {
// protect from SQL Injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysqli_real_escape_string($connection, $username);
$password = mysqli_real_escape_string($connection, $password);
$password = md5($password);
// execute the query
$query = "select * from account where username = '$username' and password = '$password'";
$result = mysqli_query($connection, $query) or die (mysql_error());
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
if (mysqli_num_rows($result) == 1) {
if ($row["username"] == $username && $row["password"] == $password) {
echo "LOGIN SUKSES";
}
} else {
echo "LOGIN GAGAL";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment