最后插入的ID

时间:2012-05-30 18:10:06

标签: php

这是我的查询

$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());

无论如何都要从这个

中选择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')";

请原谅我糟糕的英语。

2 个答案:

答案 0 :(得分:6)

mysql_insert_id()

将返回最后一个插入行的主键值。

答案 1 :(得分:1)

是的,请查看here以发现mysql_insert_id()