So I am currently working on a form that lets me login using a username and password from my database and when i check the request method it doesn't work (I realized it didn't work by putting an echo right after the check so it doesn't go through the check), Here is my PHP code :
<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST"){
$username = mysqli_real_escape_string($db,$_POST['username']);
$password = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT ID from Operateur where username = '$username' and mot_de_passe = '$password'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
if($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
And here is my form code
<div id="form">
<h2>Welcome</h2>
<form action="" method="POST">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="password">
<input type="submit" value="Log in" class="submit" name="sumbit">
<input type="button" value="Close" class="close" onclick="closeForm()">
</form>
</div>
If any more code from my part is needed to resolve this problem please tell me
So I tried to use isset($_POST[...])
but it didn't work as well and i'm currently out of ideas, as i am fairly new to php.
",$_POST['username']; I have just tried this "var_dump($_POST);" and after submitting it shows me the submitted username and password so thank you ADyson, and for the security risks, this is just a project that i am doing as an intern and i am still learning php, thanks for all the help – AchMi Jul 21 '23 at 11:54