This is my code i was trying that if I enter my email and pass where saved in my database(MySQL) will show that if I entered it correctly it shows that i logged in as that email. So i guess you can help me of where am i wrong on my coding, btw i am new in web programming so, I am greatful if you teach me the easiest to understand and the simpliest way.
<?php
$servername = "localhost";
$username = "root";
$password = "crazyjaguar";
$db = "getstarted";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// error_reporting(0);
if ($_POST['email'] && $_POST['pwd']) {
// escape
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['pwd']);
// sql email and pass
$sql = "SELECT email, password FROM gs_users";
// query esql & espl
$result = mysqli_query($conn, $sql);
// fetch_array
$row = mysqli_fetch_array($result,MYSQLI_BOTH);
if ($row['email'] != $email) {
die ("No $email registered yet!");
}
if ($row['password'] = $password) {
die ("Wrong $pmail!");
}
echo "You're logged in as $email";
mysqli_close($conn);
}
}
?>
<body>
<h1>Log In</h1>
<form action='' method='post'>
<input type='email' name='email' placeholder='Email'>
<input type='password' name='pwd' placeholder='Password'><br />
<a href='forgot.php'>Forgost Password?</a><br />
<input type='submit' name='signup' value='Signup Here!'><br />
<input type='submit' name='login' value='LogIn'>
</form>
</body>