0
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
    <div class="main-content-inner">
            <form method="post">
            <p><div>
                <input name="nametxt" id="nametxt" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
            </p></div>
            <p><div>    
                <input name="designationtxt" id="designationtxt" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
            </p></div>
            <p><div>
                <input name="designationtxt" id="descriptiontxt" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
            </p></div>

                <input id="submitbtn" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px;   " name='Submit' value='Add Member' /><br><br>

            </form>
    </div>
</div>
<?php
     global $wpdb;
    $table = $wpdb->prefix.'tboxteam';
     $data = array('name' =>  isset($_POST['nametxt']), 'designation' =>  isset($_POST['designationtxt']), 'description' =>  isset($_POST['descriptiontxt']));
     $format = array('%s','%s','%s');
     $wpdb->insert($table,$data,$format);
?>
0
<?php /* Template Name: Dummy Practice Page*/?>
<div id="main-content" class="main-content">
  <div class="main-content-inner">
        <form method="post">
        <p><div>
            <input name="nametxt" id="nametxt" type="text" style="height:30px; width: 350px; " maxlength="5" placeholder="Name" required><br>
        </p></div>
        <p><div>    
            <input name="designationtxt" id="designationtxt" type="text" style="height:30px; width: 350px; " maxlength="50" placeholder="Designation" required><br>
        </p></div>
        <p><div>
            <input name="descriptiontxt" id="descriptiontxt" type="text" style="height:30px; width: 350px; " maxlength="1000" placeholder="Description" required><br>
        </p></div>

            <input id="submitbtn" type='submit' style="height:40px; width: 130px; padding:10px; color:dodgerblue; background-color:black; border-radius:20px;   " name='Submit' value='Add Member' /><br><br>

        </form>
    </div>
 </div>
 <?php
 // Checking if form submitted 
 if(isset($_POST['Submit'])){

       // Fetching values if they are not empty.
    if( isset($_POST['nametxt']) || isset($_POST['designationtxt']) ||isset($_POST['descriptiontxt']) ){

        global $wpdb;

        $data = array('name' =>  $_POST['nametxt'], 'designation' =>  $_POST['designationtxt'], 'description' =>  $_POST['descriptiontxt'] );


        $table = $wpdb->prefix.'tboxteam';

        $format = array('%s','%s','%s');

        $wpdb->insert($table,$data,$format);
    }
 }

 ?>
0

PHP isset returns boolean value to check if the array index exists. https://www.php.net/manual/en/function.isset.php

"name" => isset($_POST["nametxt"]) ? $_POST["nametxt"] : ""

This is what you should do

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.