I'm trying to insert to a database but keep getting this error. I'm new to PHP and MySQL so have trawled through the forums here but have not found a solution.
Edit: Thanks for pointing out that I had mixed mysql and mysqli. I have amended that but still get the same error. Amended code below.
Here is the error I get:
Error: INSERT INTO user (vocID,username,password,firstname,lastname,street,city,postal,country,telephone,email)
VALUES ('VOC168','testuser','testpass', 'first', 'last', 'street', 'city', 'postal', 'country', 'telephone', 'email@g.com');
Here is my code:
/* connect to the db */
$connection = mysql_connect('localhost','user','password');
mysql_select_db('database',$connection);
$result = mysql_query("select id, vocID from user order by id desc limit 1");
while ($row = mysql_fetch_assoc($result))
{
$vocID = 'VOC'.$row['id'];
$sql = "INSERT INTO user (vocID,username,password,firstname,lastname,street,city,postal,country,telephone,email)
VALUES
('VOC168','testuser','testpass', 'first', 'last', 'street', 'city', 'postal', 'country', 'telephone', 'email@g.com')";
if (mysql_query($connection, $sql)) {
echo "New record created successfully";
}
else {
echo "Error: " . $sql . "<br>" . mysql_error($connection);
}
}
mysql_close($connection);