1<?php
2 if (!empty($_POST)) {
3 global $wpdb;
4 $table = 'contact_form';
5 $data = array(
6 'names' => $_POST['yourname'],
7 'emails' => $_POST['customer_email'],
8 'gender' => $_POST['customer_gender'],
9 'age' => $_POST['customer_age']
10 );
11 //echo "<pre>"; print_r($data);
12
13 $success=$wpdb->insert( $table, $data );
14 if($success){
15 echo 'data has been save' ;
16 }
17 } else {
18 echo "data not save";
19 }
20 ?>
21 <div class="container">
22 <div class="row ">
23 <div class="col-md-12 pb-5">
24 <form method="post">
25 Your name:<input type="text" name="yourname" id="yourname">
26 Your Email:<input type="text" id="customer_email" name="customer_email"/><br>
27 Gender:<input type="radio" name="customer_gender" value="male">Male
28 <input type="radio" name="customer_gender" value="female">Female<br>
29 Your Age:<input type="text" name="customer_age" id="customer_age"><br>
30 <input type="submit" name="submit" value="Submit">
31 </form>
32 </div>
33 </div>
34 </div>
35
1<?php
2// 2nd Method - Utilizing the $GLOBALS superglobal. Does not require global keyword ( but may not be best practice )
3$results = $GLOBALS['wpdb']->get_results( "SELECT * FROM {$wpdb->prefix}options WHERE option_id = 1", OBJECT );
4
1global $wpdb;
2
3$wpdb->insert(
4'table',
5array( 'value' => $value ),
6array( '%s' ),
7);
8
9
10
11
12