I have created a login form where a user must enter a username and password, once they click the submit button I want to store their IP Address into a mysql database that I have created.
I've tried the following, but I haven't had any luck, could someone please help? Thanks.
Login Form:
<!DOCTYPE html>
<html>
<style>
/* Header/Logo 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;
}
/*style buttons*/
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%;
}
/* set a hover effect for the button*/
button:hover {
opacity: 0.8;
}
.imgcontainer {
padding: 20px;
text-align: center;
}
/*set padding to the container*/
.container {
padding: 16px;
}
/*set the forgot password text*/
span.psw {
float: center;
padding-top: 16px;
}
</style>
<body>
<!HTML-->
<div class="header">
<h2>
<img src="vs/banner.png">
</h2>
</div>
<form action="test.php" method="POST">
<div class="imgcontainer">
<img src=
"data:image/png;base64,"base64code" 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="username@email.co.uk"
oninvalid="this.setCustomValidity('Enter a valid email address, phone number or Skype name')"
oninput="this.setCustomValidity('')"
/>
<label><b>Enter password</b></label>
<input type="password" placeholder="Enter Password" name="user_password" required place>
<input type="submit" value = "Login">
<label>
<input type="checkbox" checked="checked"> Remember me
</label>
</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 the correct email</span>
</div>
</form>
php file named test.php:
$mysqli = new mysqli( 'localhost', 'admin', 'pass', 'ip_add' );
// Check connection
if ( $mysqli->connect_error ) {
die( 'Kan niet verbinden met database. Probeer het later opnieuw. ' .
$mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
// Insert data
$sql = "INSERT INTO details (ip_add) VALUES ('{$mysqli-
>real_escape_string($_SERVER['REMOTE_ADDR'])}'";
$insert = $mysqli->query($sql);
if ( $insert ) {
echo "U bent succesvol ingeschreven! U heeft bootnummer: {$mysqli-
>insert_id}. Op de naam: . U krijgt hiervan nog een bevesteging op uw
mail, uw bootnummer kan nog veranderen";
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}
$mysqli->close();
}
?>
My database is called details and has a table column call ip_add which uses VARCHAR(255). Whenever I submit details on the login form, nothing appears in my table for my database.