Search code examples
phpmysqlwordpressmysql-insert-id

using mysql_insert_id in mysql_query


I'm trying to put some data in db but something is going wrong. This is my code:

 $insert = mysql_query("
    INSERT INTO wp_users (ID, user_login, user_pass, user_nicename, user_email, user_url, user_registered, user_activation_key, user_status, display_name) VALUES ('NULL', 'teste', MD5('teste'), 'O Meu Nome', '[email protected]', 'http://www.o_meu_site.com/', '2011-06-15 00:00:00', '', '0', 'O Meu Nome');
    ");

    $insert2 = mysql_query("
    INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES (NULL, '" . mysql_insert_id() . "', 'wp_capabilities', 'a:1:{s:13:\"administrator\";b:1;}');
    ");

    $insert3 = mysql_query("
    INSERT INTO wp_usermeta (umeta_id, user_id, meta_key, meta_value) VALUES (NULL, '" . mysql_insert_id() . "', 'wp_user_level', '10');
    ");

    ?>

The problem is: The last INSERT is using mysql_insert_id() is not using the ID from the first query, it using umeta_id. What i need to change? Please help


Solution

  • In first insert statement , you have null embedded in single quote . It will be a string value