我正在尝试插入数据库,但一直收到此错误。我是PHP和MySQL的新手所以已经在这里搜索了论坛,但还没有找到解决方案。
编辑:感谢您指出我混合了mysql和mysqli。我修改过但仍然得到同样的错误。修改后的代码如下。
这是我得到的错误:
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');
这是我的代码:
/* 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);