0

I have this test plugin that I am using to try and insert into my WordPress database. It runs without a problem but it doesn't insert and when I click on the form submit it directs me to no page found in Wordpress. Can someone help me here. I am learning this.

<?php
/**
 * Plugin Name:       Form Insert DB
 * Plugin URI:        https://myetestsite.co.za
 * Description:       Just Insert Data into Custom Form
 * Version:           1.0
 * Author:            Luthando
 * Author URI:        https://myetestsite.co.za
 */

function custom_form() {
 ?>
 <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post" style="color: #fff">
  <div class="form-group">
    <label for="name">Name </label>
    <input name="name" required="true" type="text" class="form-control" id="name"/>
  </div>
   <div class="form-group">
    <label for="surname">Surname </label>
    <input name="surname" required="true" type="text" class="form-control" id="sname"/>
  </div>
   <div class="form-group">
    <label for="phone">Phone </label>
    <input name="phone" required="true" type="text" class="form-control" id="phone"/>
  </div>
  <br/><hr/>
   <div class="form-group">
    <label for="Acc">Account Number </label>
    <input name="accnum" required="true" type="text" class="form-control" id="accno"/>
  </div>
   <div class="form-group">
    <label for="bank">Bank Name </label>
    <input name="bank" required="true" type="text" class="form-control" id="bk"/>
  </div>
  <br/><hr/>
    <div class="form-group">
    <label for="email">Email address:</label>
    <input required="true" type="email" class="form-control" id="email"/>
  </div>
  <div class="form-group">
    <label for="pwd">Password:</label>
    <input name="pass" type="password" class="form-control" id="pwd"/>
  </div>
  <div class="form-group">
    <label for="confPwd">Confirm Password:</label>
    <input type="password" class="form-control" id="pwd"/>
  </div>

  <button style="background: #08a873; margin-top: 10px; width: 100%" type="submit" class="btn btn-primary btn-lg active" role="button" aria-pressed="true">Login</button>
</form>

 <?php
}
add_shortcode('display', 'custom_form');
if($_POST['submit']) {
 global $wpdb;
 $table_name ='users';
 $name = $_POST['name'];
 $surname = $_POST['surname'];
 $phone = $_POST['phone'];
 $accno = $_POST['accnum'];
 $bank = $_POST['bank'];
 $email = $_POST['email'];
 $pass = $_POST['pass'];

 $success = $wpdb->insert("users", array(
   "name" => $name,
   "surname" => $surname,
   "phone" => $phone,
   "accnum" => $accno,
   "accnum" => $accno,
   "bank" => $bank,
   "email" => $email,
   "pass" => $pass
));
 if($success) {
 echo ' Inserted successfully';
      } else {
   echo 'not';
   }
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.