Iam doing a website in wordpress and i want to send registration data of frontend users to my database.
Please assit.

Member Avatar for diafol

Have you got a form?
Do you have a database schema we can see?
Are you using a DB abstraction layer or mysqli/PDO?
Do you have any code of your own or were you expecting us to do it for you?

This question is inadequate as it is.

commented: dd_action("gform_registration", "input_fields", 0, 30); function input_fields($entry, $form){ global $wpdb; $entry["1"] = '$us +0
commented: :) +13

There are probably hundreds, if not thousands of tutorials and information on creating custom forms that input to the datatbase using Wordpress.
Not to mention all of the Wordpress extensions out there that can do it as well.

This is the code i have that sends entries from my form to the db. but in the only 3 entries go into the db. the last one 'phone' does not.

add_action("gform_registration", "input_fields", 0, 30);
function input_fields($entry, $form){
    global $wpdb;


                    $entry["1"] = '$username';
                    $entry["2"] = '$email';
                    $entry["3"] = '$password';
                    $entry["4"] = '$phone';

   $SQL = "INSERT INTO `safaris8_wo5946`.`wp_vkfj_users` (`user_login`, `user_pass`, `user_email`, `user_phone`) 
   VALUES (NULL, '$username', '$password', '$email','$phone')";


   $wpdb->query($SQL);
   }

in the $SQL you just gave only four fields to be INSERTED so its either

  1. You delete the NULL from the VALUES so

    $SQL = "INSERT INTO safaris8_wo5946.wp_vkfj_users (user_login, user_pass, user_email, user_phone)
    VALUES ('$username', '$password', '$email','$phone')"

  2. Or you add the id field to the fiedls to be updated so

    $SQL = "INSERT INTO safaris8_wo5946.wp_vkfj_users (id, user_login, user_pass, user_email, user_phone)
    VALUES ('$username', '$password', '$email','$phone')"

commented: not working, still. i replaced this with what i had but still not working. this form is in a wordpress website. +0

@Stephano: not working in what sense. Is the form still submitting only three fields or not working at all.

commented: yes it is still submitting 3. iam realy not sure why at this point. +0
Member Avatar for diafol

Thanks for the negative rep, heh heh.

Anyhow, your 'dd' message was truncated. Perhaps you could post it as a 'post' rather than a 'comment' so we can see the code clearly.

add_action("gform_registration", "input_fields", 0, 30);
function input_fields($entry, $form){
global $wpdb;
                $entry["1"] = '$username';
                $entry["2"] = '$email';
                $entry["3"] = '$password';
                $entry["4"] = '$phone';
   $SQL = "INSERT INTO `safaris8_wo5946`.`wp_vkfj_users` (`user_login`, `user_pass`, `user_email`, `user_phone`) 
   VALUES (NULL, '$username', '$password', '$email','$phone')";
   $wpdb->query($SQL);
}

I'm not that familiar with the wpdb object, but I can't see where your variables are coming from. I can see the $wpdb object 'passed' by global (this is not a good way to do it), but then you place 'variable strings', e.g. '$username' into an array, $entry.

Your SQL contains the VALUES clause:

VALUES (NULL, '$username', '$password', '$email','$phone')

I can't see where these variables ($username, $password etc) are passed. That is, they do not exist inside the scope of the function.
You seem to be passing the $entry array, but then overwrite the values with 'variable strings'.

It looks a little confused. Perhaps it's me?

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

Uperword message is show the method from insert in database

@stephano, try echoing out the $phone value and see if there is an output. If yes, then in the database check the datatype of the phone column. And the coulumn name if it matches the exact one provided in the sql query

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.