我有一個代碼塊,它在mysql表內存儲了一些基本的用戶選擇。將信息分配給表格並創建自動遞增的ID ...如何獲取新創建的ID?
$isACompany = $_POST['isACompany'];
$hasDifBilling = $_POST['hasDifBilling'];
$stmt = $link->prepare("
INSERT INTO user_info SET
id='',
isACompany = ?,
hasDifBilling = ?'
");
if (!$stmt)
{
$error = "{$link->errno} : {$link->error}";
include "$docRoot/html/main/error.html.php";
exit();
}
if (!$stmt->bind_param("ii", $isACompany, $hasDifBilling))
{
$error = "{$stmt->errno} : {$stmt->error}";
include "$docRoot/html/main/error.html.php";
exit();
}
if (!$stmt->execute())
{
$error = "{$stmt->errno} : {$stmt->error}";
include "$docRoot/html/main/error.html.php";
exit();
}
鑑於該代碼,我將如何獲得在這種情況下新創建的ID?
我還有一個與這段代碼有關的問題,雖然它不是問題的一部分它的自我...由於前兩個變量繪製了這兩個帖子的值,並且看到這些值被硬編碼成該html並通過複選框(「1」或「0」)選擇。在將信息添加到數據庫之前,我還需要對它們進行消毒嗎?
[閱讀'$ stmt-> insert_id'](http://www.php.net/manual/en/mysqli-stmt.insert-id.php) –
@Michael這是一個屬性,而不是一個方法; - ) – DaveRandom
@DaveRandom我應該學會閱讀我自己的文檔鏈接。 –