Added custom field to user registration but field does not push information to the database

Christy

Unfortunately I have been trying to figure out what is wrong with my code all day. I'm new to php so please forgive me if the answer is obvious. Also, if more information is needed, let me know.

The following code is the registration page template for the Wordpress website I am creating. The goal was to add a custom phone number field to the form and have the number sent to the database. First, I created a new column in phpmyadmin called user_phone. Then I attempted to add the field to the code. Currently, once the new user fills out all of the info needed and hits submit, the user is redirected to the correct page and everything seems to go well. However, when I browse the users in phpmyadmin the phone number entered does not show up. Any help is appreciated!

<?php
/**
 * Template name: Register Page
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage classiads
 * @since classiads 1.2.2
 */

if ( is_user_logged_in() ) { 

    global $redux_demo; 
    $profile = $redux_demo['profile'];
    wp_redirect( $profile ); exit;

}

global $user_ID, $user_identity, $user_level, $registerSuccess;

$registerSuccess = "";


if (!$user_ID) {

    if($_POST) 

    {

        $message = "Registration successful.";

        $username = $wpdb->escape($_POST['username']);

        $email = $wpdb->escape($_POST['email']);
        /* PHONE NUMBER */
        $phone = $wpdb->escape($_POST['phone']);

        $password = $wpdb->escape($_POST['pwd']);

        $confirm_password = $wpdb->escape($_POST['confirm']);

        $registerSuccess = 1;

        $status = wp_create_user( $username, $password, $email );   
            if(empty($username)) {
                $message = "User name should not be empty.";
                $registerSuccess = 0;
            }elseif(empty($phone)) {
                $message = "Phone number should not be empty.";
            }
            elseif(isset($password) || isset($email)) {                     
                if (strlen($password) < 5 || strlen($password) > 15) {

                $message = "Password must be 5 to 15 characters in length.";

                $registerSuccess = 0;

                }

                //elseif( $password == $confirm_password ) {

                elseif(isset($password) && $password != $confirm_password) {

                    $message = "Password Mismatch";

                    $registerSuccess = 0;

                }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 

            }elseif(isset($email)) {
                if(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 
            }elseif ( is_wp_error($status) ) {
                $registerSuccess = 0;
                $message = "Username or E-mail already exists. Please try another one.";
            }
             else {
                if($registerSuccess = 1){
                $from = get_option('admin_email');
                $headers = 'From: '.$from . "\r\n";
                $subject = "Registration successful";
                $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $password";
                wp_mail( $email, $subject, $msg, $headers );

                $registerSuccess = 1;
                }
            }


        if($registerSuccess == 1) {
            $login_data = array();
            $login_data['user_login'] = $username;
            $login_data['user_password'] = $password;
            $user_verify = wp_signon( $login_data, false ); 

            global $redux_demo; 
            $profile = $redux_demo['profile'];
            wp_redirect( $profile ); exit;

        }



    }

}

get_header(); ?>

    <div class="ad-title">

                <h2><?php the_title(); ?> </h2>     
    </div>

    <section class="ads-main-page">

        <div class="container">
            <div class="log-in-logo">
                <a class="logo" href="<?php echo home_url(); ?>" title="Home">
                    <?php global $redux_demo; $logo = $redux_demo['logo']['url']; if (!empty($logo)) { ?>
                        <img src="<?php echo $logo; ?>" alt="Logo" />
                    <?php } else { ?>
                        <img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Logo" />
                    <?php } ?>
                </a>                
            </div>
            <div class="first clearfix log-in">

                <h2 class="login-title">REGISTER</h2> 
                <?php                   
                    if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
                ?>

                <div id="edit-profile" class="clearfix" >

                    <div class="span4">
                        <form class="form-item login-form" action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">

                                <?php if($_POST) { 

                                    global $redux_demo; 
                                    $login = $redux_demo['login'];

                                    echo "<div id='result' style='margin-bottom: 30px;'><div class='message'><h4>".$message." ";

                                    if($registerSuccess == 1) {
                                        echo "<a href='".$login."'>Login</a>.";
                                    }

                                    echo "</h4></div></div>";

                                } ?>

                                    <?php if($registerSuccess == 1) { } else { ?>




                                        <input id="contactName" placeholder="User Name" type="text" name="username" class="text input-textarea half" value="" maxlength="30" />

                                        <input id="phone" placeholder="Phone Number" type="text" name="phone" class="text input-textarea half" value="" maxlength="30" />


                                        <input id="email" placeholder="Email Address" type="text" name="email" class="text input-textarea half" value=""  maxlength="30" />


                                        <input id="password" placeholder="Password" type="password" name="pwd" class="text input-textarea half" maxlength="15"  value="" />


                                        <input id="password" placeholder="Retype Password" type="password" name="confirm" class="text input-textarea half" maxlength="15" value="" />



                                    <br/>


                                        <input type="hidden" name="submit" value="Register" id="submit" />
                                        <div class="clearfix"></div>
                                        <div class="btn-container"> 
                                            <button class="btn form-submit" id="edit-submit" name="op" value="Publish Ad" type="submit"><?php _e('Submit', 'agrg') ?></button>
                                        </div>


                                <?php } ?>

                        </form>


                        <div class="clearfix"></div>
                    </div>

                    <div class="span4 last">
                    <span>Already have an acount ?</span> <a class="login-a" href="">Login Now</a>




                        <div class="publish-ad-button login-page">

                            <?php

                                global $redux_demo; 
                                $login = $redux_demo['login'];
                                $reset = $redux_demo['reset'];

                            ?>



                        </div>

                    </div>

                </div>

                <?php }

                    else echo "<span class='registration-closed'>Registration is currently disabled. Please try again later.</span>";

                ?>

            </div>





        </div>

    </section>

<?php get_footer(); ?>

EDIT 1: I changed wp_create_user to wp_insert_user and called in all of the fields. However, the phone number is still not being pushed to the database.

<?php
/**
 * Template name: Register Page
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage classiads
 * @since classiads 1.2.2
 */

if ( is_user_logged_in() ) { 

    global $redux_demo; 
    $profile = $redux_demo['profile'];
    wp_redirect( $profile ); exit;

}

global $user_ID, $user_identity, $user_level, $registerSuccess;

$registerSuccess = "";


if (!$user_ID) {

    if($_POST) 

    {

        $message = "Registration successful.";

        $username = $wpdb->escape($_POST['username']);

        $email = $wpdb->escape($_POST['email']);
        /* PHONE NUMBER */
        $phone = $wpdb->escape($_POST['phone']);

        $password = $wpdb->escape($_POST['pwd']);

        $confirm_password = $wpdb->escape($_POST['confirm']);

        $registerSuccess = 1;

        $userdata = array(
            'user_login'    =>  $username,
            'user_email'    =>  $email,
            'user_phone'    =>  $phone,
            'user_pass'    =>  $password,
        );

        $status = wp_insert_user( $userdata );  
            if(empty($username)) {
                $message = "User name should not be empty.";
                $registerSuccess = 0;
            }elseif(empty($phone)) {
                $message = "Phone number should not be empty.";
            }
            elseif(isset($password) || isset($email)) {                     
                if (strlen($password) < 5 || strlen($password) > 15) {

                $message = "Password must be 5 to 15 characters in length.";

                $registerSuccess = 0;

                }

                //elseif( $password == $confirm_password ) {

                elseif(isset($password) && $password != $confirm_password) {

                    $message = "Password Mismatch";

                    $registerSuccess = 0;

                }elseif(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 

            }elseif(isset($email)) {
                if(!filter_var($email, FILTER_VALIDATE_EMAIL))
                  {
                  $message = "Please enter a valid email.";
                  $registerSuccess = 0;              
                  } 
            }elseif ( is_wp_error($status) ) {
                $registerSuccess = 0;
                $message = "Username or E-mail already exists. Please try another one.";
            }
             else {
                if($registerSuccess == 1){
                $from = get_option('admin_email');
                $headers = 'From: '.$from . "\r\n";
                $subject = "Registration successful";
                $msg = "Registration successful.\nYour login details\nUsername: $username\nPassword: $password";
                wp_mail( $email, $subject, $msg, $headers );

                $registerSuccess = 1;
                }
            }


        if($registerSuccess == 1) {
            $login_data = array();
            $login_data['user_login'] = $username;
            $login_data['user_password'] = $password;
            $user_verify = wp_signon( $login_data, false ); 

            global $redux_demo; 
            $profile = $redux_demo['profile'];
            wp_redirect( $profile ); exit;

        }



    }

}

get_header(); ?>

    <div class="ad-title">

                <h2><?php the_title(); ?> </h2>     
    </div>

    <section class="ads-main-page">

        <div class="container">
            <div class="log-in-logo">
                <a class="logo" href="<?php echo home_url(); ?>" title="Home">
                    <?php global $redux_demo; $logo = $redux_demo['logo']['url']; if (!empty($logo)) { ?>
                        <img src="<?php echo $logo; ?>" alt="Logo" />
                    <?php } else { ?>
                        <img src="<?php echo get_template_directory_uri(); ?>/images/logo.png" alt="Logo" />
                    <?php } ?>
                </a>                
            </div>
            <div class="first clearfix log-in">

                <h2 class="login-title">REGISTER</h2> 
                <?php                   
                    if(get_option('users_can_register')) { //Check whether user registration is enabled by the administrator
                ?>

                <div id="edit-profile" class="clearfix" >

                    <div class="span4">
                        <form class="form-item login-form" action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">

                                <?php if($_POST) { 

                                    global $redux_demo; 
                                    $login = $redux_demo['login'];

                                    echo "<div id='result' style='margin-bottom: 30px;'><div class='message'><h4>".$message." ";

                                    if($registerSuccess == 1) {
                                        echo "<a href='".$login."'>Login</a>.";
                                    }

                                    echo "</h4></div></div>";

                                } ?>

                                    <?php if($registerSuccess == 1) { } else { ?>




                                        <input id="contactName" placeholder="User Name" type="text" name="username" class="text input-textarea half" value="" maxlength="30" />

                                        <input id="phone" placeholder="Phone Number" type="text" name="phone" class="text input-textarea half" value="" maxlength="30" />


                                        <input id="email" placeholder="Email Address" type="text" name="email" class="text input-textarea half" value=""  maxlength="30" />


                                        <input id="password" placeholder="Password" type="password" name="pwd" class="text input-textarea half" maxlength="15"  value="" />


                                        <input id="password" placeholder="Retype Password" type="password" name="confirm" class="text input-textarea half" maxlength="15" value="" />



                                    <br/>


                                        <input type="hidden" name="submit" value="Register" id="submit" />
                                        <div class="clearfix"></div>
                                        <div class="btn-container"> 
                                            <button class="btn form-submit" id="edit-submit" name="op" value="Publish Ad" type="submit"><?php _e('Submit', 'agrg') ?></button>
                                        </div>


                                <?php } ?>

                        </form>


                        <div class="clearfix"></div>
                    </div>

                    <div class="span4 last">
                    <span>Already have an acount ?</span> <a class="login-a" href="">Login Now</a>




                        <div class="publish-ad-button login-page">

                            <?php

                                global $redux_demo; 
                                $login = $redux_demo['login'];
                                $reset = $redux_demo['reset'];

                            ?>



                        </div>

                    </div>

                </div>

                <?php }

                    else echo "<span class='registration-closed'>Registration is currently disabled. Please try again later.</span>";

                ?>

            </div>





        </div>

    </section>

<?php get_footer(); ?>
Martin Joó
$status = wp_create_user( $username, $password, $email );   

In the create user you don't use phone number! And

if($registerSuccess = 1)

is incorrect.

if($registerSuccess == 1)

is correct.

By the way WP Codex (http://codex.wordpress.org/Function_Reference/wp_insert_user)

says that you cannot use phone in wp_insert_user(). The page shows a list what you can use.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Added custom field to user registration but field does not push information to the database

From Java

FieldDoesNotExist error when using Dj-Rest-Auth registration with a custom user model that does not have a username field

From Dev

Meteor - Cannot access custom user field upon registration

From Dev

Issue with dynamically populating dropdownlist for a field in django custom user registration form

From Dev

Error for Constraint added to Field does not show for field

From Dev

Devise custom validation for a custom field in the registration form

From Dev

Adding custom registration field and check its value

From Dev

Captcha field in plone user registration form

From Dev

How can i add custom field in user registration asp.net boilerplate

From Dev

Adding custom field in default joomla 3.1.1 registration form

From Dev

Can't add custom field from registration form in AngularJS + Stormpath

From Dev

Having trouble adding a "custom" field to a Devise registration form

From Dev

How to add a custom field to devise in Rails 4 and customise the registration controller?

From Dev

GCM User Notifications: Missing "registration_ids" field

From Dev

Symfony2 - FOSUserBundle set user entity field after registration

From Dev

Rails, use a form field to set something on the user registration (devise)

From Dev

Django custom user field clashes with AbstractBaseUser

From Dev

Add Custom User Field (Dropdown) in Moodle

From Dev

Use VBO in Drupal to update custom user field

From Dev

User information does not get sent to database

From Dev

User information does not get sent to database

From Dev

displaying an extra field added to the database in opencart on the order page

From Dev

Only one field is getting added in parse.com database

From Dev

CAS username field value to be manually added to the existing user on import?

From Dev

Sitecore CustomValidator does not fire on WFFM custom field

From Dev

Custom useForm Hook does not update field value

From Dev

Does relay require an id field in the the database?

From Dev

Added field not published to client?

From Dev

Added an Image Field, getting OperationalError: Column does not exist

Related Related

  1. 1

    Added custom field to user registration but field does not push information to the database

  2. 2

    FieldDoesNotExist error when using Dj-Rest-Auth registration with a custom user model that does not have a username field

  3. 3

    Meteor - Cannot access custom user field upon registration

  4. 4

    Issue with dynamically populating dropdownlist for a field in django custom user registration form

  5. 5

    Error for Constraint added to Field does not show for field

  6. 6

    Devise custom validation for a custom field in the registration form

  7. 7

    Adding custom registration field and check its value

  8. 8

    Captcha field in plone user registration form

  9. 9

    How can i add custom field in user registration asp.net boilerplate

  10. 10

    Adding custom field in default joomla 3.1.1 registration form

  11. 11

    Can't add custom field from registration form in AngularJS + Stormpath

  12. 12

    Having trouble adding a "custom" field to a Devise registration form

  13. 13

    How to add a custom field to devise in Rails 4 and customise the registration controller?

  14. 14

    GCM User Notifications: Missing "registration_ids" field

  15. 15

    Symfony2 - FOSUserBundle set user entity field after registration

  16. 16

    Rails, use a form field to set something on the user registration (devise)

  17. 17

    Django custom user field clashes with AbstractBaseUser

  18. 18

    Add Custom User Field (Dropdown) in Moodle

  19. 19

    Use VBO in Drupal to update custom user field

  20. 20

    User information does not get sent to database

  21. 21

    User information does not get sent to database

  22. 22

    displaying an extra field added to the database in opencart on the order page

  23. 23

    Only one field is getting added in parse.com database

  24. 24

    CAS username field value to be manually added to the existing user on import?

  25. 25

    Sitecore CustomValidator does not fire on WFFM custom field

  26. 26

    Custom useForm Hook does not update field value

  27. 27

    Does relay require an id field in the the database?

  28. 28

    Added field not published to client?

  29. 29

    Added an Image Field, getting OperationalError: Column does not exist

HotTag

Archive