<?php
require('login_include_connection.php');
if (isset($_POST['btn_confirm'])) {
$user_name=$_POST['user_name'];
$user_password=sha1($_POST['user_password']);
if (empty($user_name) || empty($user_password)) {
#This validation works only if user place user name, leaving blank password will still works which is not ok
echo "Please make corect inputs!!!"; #Both fields must have inputs
} else {
$sql="INSERT into user_info (id, user_name, user_password) VALUES (null, '$user_name', '$user_password')";
$result=mysqli_query($conn, $sql); #Proceed with sql query and place record to MySQL database
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
body {
background-color: lightblue;
}
</style>
</head>
<body>
<h2>User registration</h2>
<form method="POST" action="sesija_registracija.php">
<input type="text" name="user_name">
<input type="password" name="user_password">
<input type="submit" name="btn_confirm" value="REGISTER USER NOW">
</form>
</body>
</html>
Sorry guys for bad explanation on previous question. So, as you can see there is basic registration PHP script. It requires username and password to be filled out. My form will place username in database even if there is no password value. So what is wrong with if statement, empty()
doesn't works with sha1()
or something else? All I want is to make sure that the user must fill out both fields.