• Many people has asked the same question, I have read those things and mine is different,

    I am trying to insert some values inside the database from the form but it’s not getting inserted

    I have a table in the database having 6 columns wanted to insert some values inside only of 4 columns

    **Table Name: wp_contactus**

    6 Columns
    ——-

    – id
    – firstname
    – lastname
    – email
    – query
    – reg_date

    This is the code for inserting only in the 4 columns

    4 Columns
    ———

    – firstname
    – secondname
    – email
    – query

    <?php
    function contactus_shortcode(){ ?>

    <div class=”wrap”>
    <form action=”” method=”post”>
    FirstName <input type=”text” name=”firstNametxt” value=”” />
    LastName <input type=”text” name=”lastNametxt” value=”” />
    email <input type=”text” name=”email” value=”” />
    Query <input type=”text” name=”query” value=”” />
    <input name=”Submit” type=”submit” value=”Submit”>
    </form>
    <form method=”post”>
    <?php
    global $wpdb;
    $firstName = $_POST[“firstNametxt”];
    $lastName = $_POST[“lastNametxt”];
    $email = $_POST[“email”];
    $query = $_POST[“query”];

    echo $firstName;
    $contactus_table = $wpdb->prefix.”contactus”;

    $sql = “INSERT INTO $contactus_table (id, firstname, lastname, email,

    query, reg_date) VALUES (‘2’, $firstName, $lastName, $email, $query,

    CURRENT_TIMESTAMP);”;

    $wpdb->query($sql))

    ?>
    </form>
    </div>

    <?php
    }
    add_shortcode( ‘CONUS’, ‘contactus_shortcode’ );

    ?>

The topic ‘Insert Query not working in the form’ is closed to new replies.