[solved] php – Adding a new wordpress user through HTML form

Rate this post

I want to add a new WordPress user to the table wp_users through HTML form but for some reason, it just doesn’t work. What could be wrong? Do I need to insert other inputs? Or maybe to create a different table for this?

This is my HTML code:

 <span class="bottomForm">
            <p style="color:red; font-weight: bold;">
                < חזרה לעגלת הקניות </p> <button class="bottomButton" type="button" onclick="submitForm()"
                    לאפשרויות משלוח</button>

    <script type="text/javascript">
        function submitForm() {
            var email = $('input[name=user_email]').val();
            var password = $('input[name=user_pass]').val();
            var formData = {
                email: user_email,
                password: user_pass
                url: "http://localhost/quatro/api/submit.php",
                type: 'POST',
                data: formData,
                success: function (response) {



My PHP code:

$host = "localhost";
$username = "root";
$password = "";

try {
    $conn = new PDO("mysql:host=$host;dbname=quatro", $user_email, $user_pass);
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();

$response = array('success' => false);

if (isset($_POST['user_email']) && $_POST['user_email'] != '' && isset($_POST['user_pass']) && $_POST['user_pass'] != '') {
    $sql = "INSERT INTO wp_users(user_email user_pass,) VALUES('" . addslashes($_POST['user_email']) . "', '" . addslashes($_POST['user_pass']) . "')";

    if ($conn->query($sql)) {
        $response['success'] = true;

echo json_encode($response);```

Click Here to see answer


Mazi has nine years of web development experience with the past five years spent honing his skills with WordPress plugins and themes. He's an expert in WooCommerce and is the author of the Simple Sales Tax plugin, a popular sales tax compliance solution for WooCommerce. Brett understands the importance of excellent communication, prides himself on producing high-quality code, and is comfortable working solo or as part of a team.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button