2012-05-30 163 views
0

這是我的查詢最後插入的ID

$vipinsert = "INSERT INTO `$amxadmins` (`id`, `password`, `access` , `flags` ,`steamid` , `ashow` , `created` , `expired` , `days`) VALUES ('', '$logged[password]', '$accessvip', '$flagsvip' , '$logged[username]' , '$ashowvip' , '$createdvip' , '$expiredvip' , '$daysvip')"; 
    mysql_query($vipinsert) or die(mysql_error()); 
    $vipselect = mysql_query("SELECT * from `$amxadmins` WHERE steamid = '$logged[username]'") or die(mysql_error()); 
    $custom1 = ''; 
    $static1 = 'no'; 
    $row = mysql_fetch_assoc($vipselect); 
    mysql_query("INSERT INTO `$admins_servers` (`admin_id`, `server_id`, `custom_flags`, `use_static_bantime`) VALUES ('$row[id]', '$server', '$custom1', '$static1')")or die(mysql_error()); 

反正有從這個

$vipinsert = "INSERT INTO `$amxadmins` (`id`, `password`, `access` , `flags` ,`steamid` , `ashow` , `created` , `expired` , `days`) VALUES ('', '$logged[password]', '$accessvip', '$flagsvip' , '$logged[username]' , '$ashowvip' , '$createdvip' , '$expiredvip' , '$daysvip')"; 

原諒我的英語不好選擇ID。

+1

歡迎堆棧溢出! 'mysql_ *'函數不再被維護,並且社區已經開始[棄用過程](http://goo.gl/KJveJ)。相反,您應該瞭解[準備好的語句](http://goo.gl/vn8zQ)並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli的)。如果你不能決定,[本文](http://goo.gl/3gqF9)將有助於選擇。如果你想學習,[這裏是一個很好的PDO相關教程](http://goo.gl/vFWnC)。 – vascowhite

回答

6
mysql_insert_id() 

將返回最後插入行的主鍵的值。

1

是的,看看here發現mysql_insert_id()