I've create a HTML page which allows the user to type a username and password. When the user clicks the login button I need to put the username and password into a mysql database.
When I test it by typing the IP address of the website and entering username and password and press the login button it just goes to a blank page (this being the IPADDRESS/adduser.php. When I check the database nothing is entered.
I also want to redirect the user to a different page rather than to a blank page
I'm pretty new to this, but seem to have hit a brick wall, wondering if someone could help. Thanks.
HTML file:
<!DOCTYPE html>
<html>
<style>
/* Header/Title */
.header {
padding: 2px;
text-align: center;
background: rgb(49, 48, 48);
color: white;
font-size: 15px;
}
form {
border: 5px solid #f1f1f1;
background-color: white;
font-family: Verdana, Geneva, Tahoma, sans-serif;
text-align: center;
}
input[type=text],
input[type=password] {
width: 40%;
padding: 12px 20px;
margin: 8px 0;
display:block;
border: 1px solid #ccc;
box-sizing: border-box;
}
body{
background-color: rgb(180, 46, 46);
}
button {
background-color: #265ec5;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 10%;
}
button:hover {
opacity: 0.8;
}
.imgcontainer {
padding: 20px;
text-align: center;
}
.container {
padding: 16px;
}
span.psw {
float: center;
padding-top: 16px;
}
</style>
<body>
<div class="header">
<h2>
<img src="vs/banner.png">
</h2>
</div>
<form action="adduser.php" method="POST">
<div class="imgcontainer">
<img src=
"LINK TO IMAGE" width="250" height = "70"
alt="Avatar" class="avatar">
</div>
<h2 style="text-align:center;" > Sign In </h2>
<div class="container">
<label><b> Username</b></label>
<input type="text" name="user_name" required placeholder="enter valid username"
oninvalid="this.setCustomValidity('Enter a valid email address')"
oninput="this.setCustomValidity('')"
/>
<label><b>Enter password</b></label>
<input type="password" placeholder="Enter Password" name="user_password" required place>
<button type="submit">Login</button>
</div>
<div class="container" style="background-color:#f1f1f1">
<span class="psw">Forgot <a href="#">password?</a></span>
<p></p>
<span class="usn_info">You must login using with valid username</span>
</div>
</form>
</body>
</html>
php file:
<?php
$host= 'localhost';
$user = 'root';
$pass = 'admin';
$database = 'logins';
$table='user_login';
$conn = mysqli_connect($host, $user, $pass, $database);
if ($conn) {
die("Database connection failed: Insert User : Error = " .
mysqli_error());
}
$user_name=$_POST["user_name"];
$user_password=$_POST["user_password"];
$sqlquery = "INSERT INTO user_login (user_name, user_password)
VALUES ('$user_name','$user_password')";
if (mysqli_query($conn, $sqlquery))
{
echo "user added";
}
mysqli_close($conn);
?>