This problem i am facing is quite unusual to me. What i am actually trying to do is inserting data into mysql database table through the HTML form.
I have a database and i am trying to insert data into it but it always shows that "duplicate entry error".
the problem is despite checking that the information i'm entering is unique it shows that error.When i check my database table i can see that every time the entries are incrementing the id by 2. I have no idea why is my query inserting data twice and making the primary key increment by 2 and Please help i want every thing to be normal.
I can't fix it please help me.
here is my html code for the form
<form class="form-horizontal" name="RegisterCandidate" action="../processors/process_register_candidate.php" method="post" enctype="application/x-www-form-urlencoded">
<div class="form-group">
<label for="Fname" class="control-label col-sm-4">
First Name
</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="Fname" tabindex="1" autofocus required placeholder="First Name" />
</div>
</div>
<div class="form-group">
<label for="Lname" class="control-label col-sm-4">
Last Name
</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="Lname" tabindex="2" required placeholder="Last Name" />
</div>
</div>
<div class="form-group">
<label for="Photo" class="control-label col-sm-4">
Photograph
</label>
<div class="col-sm-8">
<input type="file" class="form-control" name="Photo" tabindex="3" placeholder="Select Photo" />
</div>
</div>
<div class="form-group">
<label for="DOB" class="control-label col-sm-4">
Date of Birth (DD-MM-YYYY)
</label>
<div class="col-sm-8">
<input type="date" class="form-control" name="dob" tabindex="4" required />
</div>
</div>
<div class="form-group">
<label for="password" class="control-label col-sm-4">
Password
</label>
<div class="col-sm-8">
<input type="password" class="form-control" name="password" tabindex="5" required placeholder="Password" />
</div>
</div>
<div class="form-group">
<label for="contact" class="control-label col-sm-4">
Contact No.
</label>
<div class="col-sm-8">
<input type="tel" class="form-control" name="contact" tabindex="6" required placeholder="Contact Number" />
</div>
</div>
<button type="submit" name="register" class="btn btn-success" style="float:right; margin-right:30%;">
Register
</button>
</form>
here is the copy of my php-mysql code
<?php
require_once "../web_config/web.config.php";
$conn = connect();
$fname = $_POST["Fname"];
$lname = $_POST["Lname"];
$dob = $_POST["dob"];
$password = $_POST["password"];
$contact = $_POST["contact"];
$insert = " INSERT INTO `candidates`
(
`Fname`,
`Lname`,
`dob`,
`password`,
`contact`
) VALUES (
'$fname',
'$lname',
'$dob',
'$password',
'$contact'
)
";
try{
$st = $conn->query($insert);
$st->execute();
} catch(PDOException $e) {
echo "//Failed to insert data due to ".$e->getMessage();
}
echo $fname." ".$lname;
#header("Location:../src/student_login.php");
?>
please help me out with this. Thank you.