5
Contributors
9
Replies
40
Views
2 Years
Discussion Span
Last Post by Gideon_1
1

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.

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

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.

0

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);
   }
1

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')"

Votes + Comments
not working, still. i replaced this with what i had but still not working. this form is in a wordpress website.
1

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

Votes + Comments
yes it is still submitting 3. iam realy not sure why at this point.
0

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?

0
<?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();
?>
0

@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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.