I'm trying to get the last insert id from a plugin I'm in the process of creating for vBulletin in PHP. For some reason it doesn't seem to be working... Any ideas how I go about it?
$db->query_write($sql_i);
$db->insert_id
Full Code:
$sql_i = "INSERT INTO classifieds_item (".$i_fieldnames.",`date_posted`) values (".$i_values.",NOW())";
$db->query_write($sql_i);
header("location: classifieds.php?class_act=add_img&id=".$db->insert_id);
This is using the standard vBulletin database class.
Any ideas?
insert_id() is a function, so
header("location: classifieds.php?class_act=add_img&id=".$db->insert_id());
should work. The crucial point is the difference between $db->insert_id and $db->insert_id().
Have you tried mysql_insert_id()
: http://php.net/manual/en/function.mysql-insert-id.php
It will return the last id for an AUTO_INCREMENT
column by the previous INSERT
.
Worth noting that the PHP documentation also suggests using alternatives as this method is now discouraged.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.