I have tried (as my first project) decided to make a simple login / logout proect. This is what i've done so far and it works wonders, but everytime you visit the page it registers with an empty usename and pass and only the can you register, the pass is obviously empty but i can't seem to be able to make use of empty(); Any ideas?
<html>
<head>
<title>Quick Register</title>
</head>
<body>
<form action="/register.php" method = "post">
<b>Quick.</b>
<p>USERNAME</p>
<input type="text" name="usernameInput" size="30">
<p>PASSWORD</p>
<input type="password" name="passwordInput" size="30">
<p><input type='submit' name='submit' value = "Send"></p>
</form>
<?php
if (isset($_POST['submit']))
{
$date_missing = array();
if (empty($_POST['usernameInput']))
{
$data_missing[] = "Username";
}
else
{
$username = trim($POST['usernameInput']);
}
if (empty($_POST['passwordInput']))
{
$data_missing[] = "Password";
}
else
{
$password = trim($POST['passwordInput']);
}
if (empty($data_missing))
{
require_once ("config.php");
if(empty($password)!=0)
{
$query = "INSERT INTO users (username, password,created_at) VALUES(?, ?,NOW());";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_bind_param($stmt, "ss", $username, $password);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
}
if ($affected_rows && empty($password)<>0)
{
echo ($password."Regee");
mysqli_stmt_close($stmt);
mysqli_close($link);
}
}
else
{
echo "Nu ma lasa gol boss";
foreach($data_missing as $missing)
echo($missing);
}
}
?>
</body>
</html>