• Resolved Bloke

    (@bloke)


    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)
  • Thread Starter Bloke

    (@bloke)

    I have downloaded and copied all the files. Only on my local host, added a new item won’t record and ID. Is there anything maybe in the database I need to change? There are are only 3 files of the plugin that adds the products and I compared each file.

    Thread Starter Bloke

    (@bloke)

    I figured it out. Had to do with entering the values for the item. I added a new column and didn’t account for that. So it was failing to enter the item with a new ID.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘select last insert ID’ is closed to new replies.