我已经创建了一个注册页面,其中一切正常。只想让这个小插件返回id(设置为自动增量)。我该怎么做呢?
$sql = "INSERT INTO accounts (street1, suburb, city, postcode, username) VALUES(?, ?, ?, ?, ?)";
if (! $accres = $connection->prepare($sql)){
$userinfo = "<font color = red>Account preparation failed: (" . $connection->errno . ") " . $connection->error . "</font>";
showRegisterForm ( $userinfo );
} else {
$accres->bind_param("sssss", $address, $suburb, $city, $postcode, $username);
$accres->execute();
}
答案 0 :(得分:2)
您可以从连接变量中读取它:
//execute query then:
$id = $connection->insert_id;