I get the error of Duplicate entry '' for key 1 when running a mysql query
this comes from a form that has textboxes and then tries to save to student table in mysql.
this comes from a form that has textboxes and then tries to save to student table in mysql.
Code:
$id=mysql_real_escape_string($_POST['txtstudentid']);
$password=mysql_real_escape_string($_POST['txtpassword']);
$dob=mysql_real_escape_string($_POST['txtdob']);
$firstname=mysql_real_escape_string($_POST['txtfirstname']);
$lastname=mysql_real_escape_string($_POST['txtlastname']);
$house=mysql_real_escape_string($_POST['txthouse']);
$town=mysql_real_escape_string($_POST['txttown']);
$county=mysql_real_escape_string($_POST['txtcounty']);
$country=mysql_real_escape_string($_POST['txtcountry']);
$postcode=mysql_real_escape_string($_POST['txtpostcode']);
// Build an sql statment to add the student details
$sql="INSERT INTO student(studentid,password,dob,firstname,lastname,house,town,county,country,postcode) VALUES('$id','$password','$dob','$firstname','$lastname','$house','$town','$county','$country','$postcode')";
$result = mysql_query($sql,$conn);
if($result){
echo"<br/>Your details have been updated";
echo "<BR>";
echo "<a href='Home.html'>Back to main page</a>";
} else {
echo "There has been an error <br/>";
print mysql_error();
}
// close connection
mysql_close($conn);
?>
Comment