select last insert ID
-
I am having a problem with this part. I have three sites that use the same functions and code. This one site every time I try to post a new item the ID shows as “O” in the database. This is only on my local version. Now that I have items listed with ID of “0” will I be able to get the last inserted ID? The same version of this site works fine online.
$wpdb->query($wpdb->prepare($query)); $lastId = $wpdb->get_var("SELECT LAST_INSERT_ID() FROM ". PRODUCTS); while (list ($key,$val) = @each ($cats)) { if(isset($_REQUEST['editProductValue'])) $assocQuery = "INSERT INTO ". CAT_ASSOC ."(<code>prod_id</code>, <code>cat_id</code>) VALUES('$editId', '". $val. "')"; else $assocQuery = "INSERT INTO " .CAT_ASSOC ."(<code>prod_id</code>, <code>cat_id</code>) VALUES('$lastId', '". $val. "')"; $wpdb->query($assocQuery); }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘select last insert ID’ is closed to new replies.