I can't get my loginfunction to work. For some reason, it doesn't properly create the session. I hope someone finds the error in my code and is able to help me. Don't worry about all the Gets, and the unencrypted password (i am not selecting it encrypted only inputing it) it will come as soon as i got the php to work.... I just entered a database input with an unencrypted password and an username. for some reason i always get the output"your username or password is wrong". It's refusing to go into the if case, and it's not creating the session therefore.
if(isset($_GET["login"])){
login_DB();
}
//funktionsdefinition des logins
function login_DB(){
if (empty ($_GET['username'])||empty ($_GET['password'])){
$error = "Please enter a Username and a Password";
echo $error;
}
else
{
require("dbconnect.php");
$username = $_GET['username'];
$password = $_GET['password'];
//Sql query zur datenbankabfrage
$query = "select * from login where password='$password' AND username='$username'";
$result = $con->query($query);
var_dump($result);
if ($result->num_rows > 0) {
session_start();
// Store Session Data
$_SESSION['login_user']= $username; // Initializing Session with value of PHP Variable
echo $_SESSION['login_user'];
echo"you are no logged in";
}
else {
echo "Your username or password is wrong";
}
}
}
<div id="loginregisterdiv">
<form action="M133_A_140.php" method="get">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="login" value="Login" onclick="insert()" />
<input type="submit" name="register" value="Registrieren"/>
</form>
</div>