i'm trying to make a login page work with php and mysql, but it doesn't wanna work, i'm new to php. All i want is when a correct user and pass is entered, display/echo that user's level
mysql:image
db.php:
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$dbname = "maindb";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
# open database like before.
$web_username=$_POST['username'];
if ($web_username=="") die(); # one bit of error handling.
$web_password=$_POST['password'];
$sql = "SELECT id, level FROM users WHERE name = ? AND password = ?";
$stmt = $conn->prepare ($sql ); # needs error check
$stmt->bind_param("ss", $web_username, $web_password);
$stmt->execute(); # needs error check
if ($stmt->num_rows==1) {
$stmt->bind_result($id, $level);
$stmt->fetch();
printf ("id is %s, level is %s\n", $id, $level);
}
?>
index.html:
<html>
<body>
<form method='post' action='db.php'>
Username: <input type='text' name='username' placeholder='username'><br>
Password: <input type='password' name='password' placeholder='password'><br>
<input type="submit" value="Submit" />
</form></body></html>