I'm getting the error: Duplicate entry '0' for key 'PRIMARY'
the query which is being ran is:
INSERT INTO cars (make, model, Reg, colour, miles, price, dealerID, mpg, mph) VALUES ('cake', 'pie', 'k', 'blue', '100', '10', '9', '40', '80')
The primary key for the table is carIndex and is set as Auto Increment, as-well as not being mentioned in the query I don't understand this error. It keeps trying to place the new entry at the very start of the table instead of just adding it on.
The PHP which generates this query is:
function addcar()
{
session_start();
if (isset($_SESSION['user']))
{
$db = mysqli_connect('localhost', 'root', '', 'cdb')
or die('Error connecting');
$query = "INSERT INTO cars (make, model, Reg, colour, miles, price, dealerID, mpg, mph)
VALUES (
'".$_POST['manufacture']."',
'".$_POST['model']."',
'".$_POST['reg']."',
'".$_POST['colour']."',
'".$_POST['mileage']."',
'".$_POST['price']."',
'".$_SESSION['dealerID']."',
'".$_POST['mpg']."',
'".$_POST['mph']."'
)
";
$addcarquery = mysqli_query($db, $query)
or die("Error in query: '$query'");
}
}
Edit:
Table structure, sure how to do the visual example I've seen before so I'll describe.
It is made up of 8 fields, the 7 seen in the query + the Primary key of carIndex, currently the only relation ship is between dealerID and a table called dealers, with carIndex set as Auto Increment.
Edit2:
So.... I restarted XAMPP... and well yeah all seems to work fine now -.-' Sorry y'all.