Hello Friends,
Please I solicit your kind review. I wrote the code below to help me check for duplicate record entry so my users will not enter same record twice in a year buts the code is neither posting the record not checking if there is any duplicate entries.
Here is how the system work. The application on its own allows multiple entries but once in a year. Every year members of a church gather for a conference and the system is used to capture their details. So for every participants, the system will capture their detail for that year once. If a participants details is entered twice the system should check the RegNo and Year fields to be sure the record has not been posted for that year. But its not working
Please I need help on this.
if(isset($_POST['submit'])) {
{
$con = mysql_connect('localhost', 'root', '', 'rmwworg_dbms') or die('Error connecting to MySQL server');
$Camp = $_POST['Camp'];
$Hostel = $_POST['Hostel'];
$Validate = $_POST['Validate'];
$Event_Title = $_POST['Event_Title'];
$Regno = $_POST['regno'];
$Title = $_POST['Title'];
$Surname = $_POST['surname'];
$OtherNames = $_POST['OtherNames'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$Age = $_POST['Age'];
$State = $_POST['State'];
$Country = $_POST['Country'];
$Assembly= $_POST['Assembly'];
$Sex = $_POST['Sex'];
$MaritalStatus = $_POST['MaritalStatus'];
$Phone = $_POST['Phone'];
$Email = $_POST['Email'];
$photo2 = $_POST['photo2'];
$datetime = $_POST['datetime'];
$Year = $_POST['Year'];
$validatedby = $_POST['validatdby'];
$category = $_POST['category'];
$result = mysql_query("SELECT * FROM validatedparticipants WHERE RegNo = '$regno' AND Year = year(now())"); //check for duplicates
$num_rows = mysql_num_rows($result); //number of rows where duplicates exist
if($num_rows==0) { //if there are no duplicates...insert
{
$sql="INSERT INTO validatedparticipants (Camp, Hostel, Validate, Event_Title, RegNo, Title, Surname, OtherNames, Address, City, Age, State, Country, Assembly, Sex, MaritalStatus, Phone, Email, photo2, datetime, Year, validatdby, category)
VALUES ('$Camp', '$Hostel', '$Validate', '$Event_Title', '$regno', '$Title', '$surname', '$OtherNames', '$Address', '$City', '$Age', '$State', '$Country', '$Assembly', '$Sex', '$MaritalStatus', '$Phone', '$Email', '$photo2', '$datetime','$Year','$validatedby','$category')";
$result1 = mysql_query($con, $sql) or die('Error querying database.');
mysql_close($con);
}
}
else
{
echo"The Participant added";
}
}
header("valpartcard.php?RegNo=" . $row_rsValidateParticipant['RegNo'] . "");
}