I am trying to make my own auto increment with php and sql. It keeps returning a error Error: Duplicate entry '1' for key 'PRIMARY'. It would be great if you could help me. Thanks in advance.
<?php
$con = mysql_connect("localhost", "", "");
if (!$con)
{
die ('Count not connect: ' . mysql_error());
}
mysql_select_db("", $con);
$sql2= "SELECT MAX (staffID) FROM staffDetails";
$sql3= $sql2 + 1;
$sql= "INSERT INTO staffDetails (staffID, surname , firstname, address , phoneNumber , jobTitle , username , password)
VALUES
($sql3,'$_POST[surname]','$_POST[firstname]','$_POST[address]','$_POST[phoneNumber]','$_POST[jobTitle]','$_POST[username]','$_POST[password]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<script type="text/javascript">
alert("Member has been added");
history.back();
</script>
<?php
mysql_close($con);
?>

New Topic/Question
Reply



MultiQuote




|