Thursday, November 28, 2019

Wordpress custom form insert into database table

 <?php

if(isset($_POST['submit'])){
global $wpdb;
$table='wp_cbg7ccqh4q_zipcode';
$post_data=array(
'zipcode_val' => $_POST['zipcode_val']
);
$results =$wpdb->insert( $table, $post_data);
      if($results){
    //   echo 'Zip Code added Successfully';
    $text_zip="ZipCode added Successfully";
echo '<script type="text/javascript">alert("'.$text_zip.'")</script>';
        } else {
        echo 'Not insert';
        }
}

?>
        <form action="" id="location_forms" method="post" autocomplete="off">
    <table>
        <tr>
            <td><label for="organizationname">Add Zip Code:</label></td>
            <td><input type="text" name="zipcode_val" id="zipcode_val" value="" onkeypress="return event.charCode >= 48 && event.charCode <= 57" /> </td>
        </tr>
     
        <tr>
            <td><button type="submit" id="order_loc" class="check-btn" name="submit">Submit</button></td>
        </tr>
    </table>
</form>

No comments:

Post a Comment