I'm creating a sign up sheet system for my website. Each sign up sheet is given an ID number. When a user signs up it sends the username and the ID number to a database. However I want to stop duplicate entries so that the same user can only sign up to an event once. I can't use a WHERE statement in the SQL query and I was just wondering what the best way to tackle this would be. I can't use primary or unique keys as then they can only sign up for one event, or only one event can be signed up for. Thanks in advance.
This is the code for the page
<?php
session_start();
$user = $_POST['username'];
$id = $_POST['id'];
if(empty($user) == FALSE )
{
$con=mysqli_connect("localhost","emuas","flgdls","EMUAS_signUp");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO SIGN_UP_TEST (EventID, User, Comments)
VALUES
('$_POST[id]','$_SESSION[username]','$_POST[comments]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header("Location: {$_SERVER['HTTP_REFERER']}");
}
else
{
header("Location: {$_SERVER['HTTP_REFERER']}");
}
?>