$wordpress_user_db_query = mysql_query("INSERT INTO cedsite_wrdp1.wp_users (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES
('".$username."', '".md5($pass)."', '".$username."', '".$email."', '', '".$date."', '', 0, '".$username."');");

Using PHP I am trying to do that, but it isn't working. Can someone help?

Dani AI

Generated

Short summary and a safe fix: inserting directly into the WordPress users table is fragile and usually unnecessary. The thread shows two common pitfalls: quoting/concatenation mistakes that produce literal text instead of a hashed password, and doing raw SQL with the old mysql_* API (which is deprecated and removed on modern PHP). was right to ask where the code runs — if it runs inside WordPress you should use the WP API; if it runs outside you must load WP correctly or open a proper DB connection.

Why the suggestions in the replies fail: ’s version would end up inserting the text "md5(...)" (or md5(plainpassword)) instead of a real hash if the function call is placed inside the query string. ’s “use only single quotes” advice misses the point: quoting in PHP is about the outer PHP string and how you build the query, not SQL quoting alone. Both answers leave security and hashing wrong.

Recommended approach (run this inside a theme/plugin or after loading WP): use WordPress functions so passwords are hashed correctly and capabilities are set for you.

// run where WP is loaded (theme/plugin)
$user_id = wp_insert_user(array(
  'user_login'     => $username,
  'user_pass'      => $password,   // give plain text; WP hashes it
  'user_email'     => $email,
  'display_name'   => $username,
  'user_registered'=> current_time('mysql')
));
if ( is_wp_error($user_id) ) {
  error_log('wp_insert_user failed: ' . $user_id->get_error_message());
}

If you absolutely must write SQL: never use plain md5, and do not hand-roll queries with variables unescaped. Use $wpdb->insert and wp_hash_password($password), check the correct table prefix ($wpdb->users), and examine $wpdb->last_error (or mysqlerror() if still using mysql*) to get the server error. Also verify your DB connection, selected database, and unique constraints on user_login/user_email.

Recommended Answers

All 4 Replies

Bump, this is urgent!

we need more information, how are you trying to use this? I see you are using Wordpress.

i.e. is it within a post? is it within a page? is it in a widget? is it in a custom template you are modifying on the backend? All would have different answers. I'll help if I can

try this

$wordpress_user_db_query = mysql_query("INSERT INTO cedsite_wrdp1.wp_users ( user_login , user_pass , user_nicename ,  user_email , user_url , user_registered , user_activation_key , user_status, display_name ) VALUES ('$username', 'md5($pass)', '$username', '$email', '', '$date', '', 0, '$username');");

Use only single quotes for inserting, not double quotes... this will give parser error... This will surely work fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.