I've made a database, so people can join a competition (it's a schoolproject), and I've added something so you can't have twice the same emailadress, but when there is a duplicate input, the ID will still count. So for example someone wants to join with the email "helloworld@gmail.com" and he gets the ID 2 and then he tries again, he will get an error that that emailadress is already taken, but the next person who wants to sign in, will get the ID 4 instead of 3. If you are able to make it so the database saves an IP from the one who signs is, I'm fine with it too, cause thats what I actually am trying to make. But as long as you solve the problem, I'm happy. Thank you! (I dunno why but the code always messes up...
<?php
// Only process the form if $_POST isn't empty
if ( ! empty( $_POST ) ) {
// Connect to MySQL
$mysqli = new mysqli( '***', '***', '***', '***' );
// Check our connection
if ( $mysqli->connect_error ) {
die( 'Kan niet verbinden met database. Probeer het later opnieuw. ' .
$mysqli->connect_errno . ': ' . $mysqli->connect_error );
}
// Insert our data
$sql = "INSERT INTO inschrijven ( naam, email, aantal ) VALUES ( '{$mysqli->real_escape_string($_POST['naam'])}', '{$mysqli->real_escape_string($_POST['email'])}', '{$mysqli->real_escape_string($_POST['aantal'])}' )";
// validate agree unless you want to add 'checked' to one of the values
$insert = $mysqli->query($sql);
// Print response from MySQL
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. Hopelijk zien we u op de BotenBouwDag 2016!";
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}
$mysqli->close();
}
?>
<HTML>
<head>
<title>
Welkom op de officiëlea site van de BotenBouwDag 2016
</title>
</head>
<body>
<form method="post" action="">
<input name="naam" id="naam" type="text">
<input name="email" id="email" type="email">
<input name="aantal" id="aantal" type="number">
<input type="radio" name="eten"> Ja
<input type="radio" name="eten"> Nee
<input type="submit" id="submit" value="Verstuur Informatie">
</form>