No Errors while registering plugin, and still does not update wordpress table

this is my plugin and it is driving me nuts… It creates a new table upon activation but afterwards it dose not insert or update data and there is no error on the page.. Please help!

Includes

<?php


            wp_register_style( 'andreiplugin', plugin_dir_url( FILE ) . 'pluginAndrei.css' );
            register_activation_hook(__FILE__, 'andreiPlugin_table');

Here i make the table

function andreiPlugin_table() {
            require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
            global $wpdb;
            global $table_name;

            $table_name = $wpdb->prefix."myusers";
            if($wpdb->get_var("SHOW TABLES LIKE '.$table_name'") != $table_name) {

                $sql = 'CREATE TABLE '.$table_name.'(
                        id INTEGER NOT NULL, 
                        name VARCHAR(30) NOT NULL,
                        email VARCHAR(30),
                        gender VARCHAR(50),
                        reg_date TIMESTAMP,
                        PRIMARY KEY  (id))';


                    dbDelta($sql);

                    add_option("andreiPlugin_version", "1.0");

                    }




            }

The form function:

            function userForm(){


            $name = $_POST['username'];
            $email = $_POST['email'];
            $gender = $_POST['gender'];
            $insert = 1;
            global $wpdb;

            $result_db_table = $wpdb->prefix . "myusers";
            $query_data = $wpdb->get_results($wpdb->prepare("
                        SELECT *
                        FROM " .$result_db_table, OBJECT )); 



            while ($query_data) {

                    if($name == $query_data['name']){

                        $insert = 0;

                        $wpdb->update( 
                            '$table_name', 
                            array( 
                                'name' => '$name',
                                'email' => '$email',    
                                'gender' => '$gender'    
                                ));
                    }


                }

                if($insert==1){

                    $wpdb->insert( 
                '$result_db_table', 
                array( 
                    'name' => '$name', 
                    'email' => '$email',
                    'gender' => '$gender'
                ));

                    }

            }


            ?>

I included also the html in the plugin..

            <html lang="en">



            <head>



                <meta http-equiv="content-type" content="text/html; charset=utf-8">

                <title>formsubmit</title>

And made the form validation in javascript

                <script type="text/javascript">
                    function check_info(){
                        var username = document.getElementById('username').value;
                        var email = document.getElementById('email').value;

                        var male = document.getElementById('auto_renew_male').checked;
                        var female = document.getElementById('auto_renew_female').checked;
                        if (male==false&&female==false) {

                        alert('Please specify your gender');
                            return false;
                        }
                        if (username==""|| email=="") {

                            alert('Please fill in all fields')
                            return false;
                        }
                        else{

                            return true;
                        }
                    }

                </script>

            </head>



            <body>
                <div id="wrapper"> <!--style="float:left; margin-left: 300px;"-->

And.. the form itself

            <form action="" method="post" onsubmit="return check_info();">

                <p>Full Name:</p><input type="text" name="username" id="username"/>
                <p>Email:</p><input type="text" name="email" id="email"/>
                <p>What is your gender</p>
                Male<input type="radio" name="gender" value="male" id="auto_renew_male"><br/>
                Female<input type="radio" name="gender" value="female" id="auto_renew_female"><br/>
                        <input type="submit" value="login" name="submitButton"/>
            </form>

                </div>

            </body>



            </html>

And finally here I execute the userForm function.. i tried calling it simply after the if() by userForm(); and still no effect… also it echoes “thank you…” after the button is pushed

            <?php


                if(isset($_POST['submitButton'])){
                    register_activation_hook(__FILE__, 'userForm');


                    echo "Thank you for your submission!";
                }


            ?>


Source: wpdb

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.