Неопределенный индекс: отправить в C: \ xampp \ htdocs \ index.php в строке 29 - PullRequest
1 голос
/ 04 июля 2019

Примечание: неопределенный индекс: отправить в C: \ xampp \ htdocs \ index.php в строке 29

<?php
/**
 * Plugin Name:       Form Insert DB
 * Plugin URI:        http://solutionshint.com
 * Description:       Just Insert Data into Custom Form
 * Version:           1.0
 * Author:            SolutionsHint
 * Author URI:        http://solutionshint.com
 */

function custom_form() {
?>
    <form action ="<?php echo $_SERVER['REQUEST_URI']; ?>" method ="post">
         <label for name=""> Name:</label><br>
         <input type = "text" name = "name" id = "name" placeholder = "Enter Name">
         <label for name=""> City:</label><br>
         <input type = "text" name = "city" id = "city" placeholder = "Enter City">
         <label > State:</label><br>
         <input type = "text" name = "state" id = "state"  placeholder = "Enter State">
         <label> Age:</label><br>
         <input type = "text" name = "age" id = "age"  placeholder = "Enter Age">
         <input type = "submit" name = "submit" value = "Insert">
    </form
<?php
}

// add_shortcode('display', 'custom_form');

if($_POST['submit']) {
    global $wpdb;
    $table_name ='student';
    $name = $_POST['name'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $age = $_POST['age'];

    $success = $wpdb->insert("student", array(
       "name" => $name,
       "city" => $city,
       "state" => $state,
       "age" => $age ,
    ));
    if($success) {
        echo ' Inserted successfully';
    } else {
        echo 'not';
    }
}
?>

Это мой код, я новичок в php, и я разрабатываю плагин, который будет сохранять формуданные в базу данных, но я получаю сообщение об ошибке

Примечание: неопределенный индекс: отправить в C: \ xampp \ htdocs \ index.php в строке 29

1 Ответ

0 голосов
/ 04 июля 2019

Попробуйте этот код. вам нужно использовать if(isset($_POST['submit'])) {

<?php
/**
 * Plugin Name:       Form Insert DB
 * Plugin URI:        http://solutionshint.com
 * Description:       Just Insert Data into Custom Form
 * Version:           1.0
 * Author:            SolutionsHint
 * Author URI:        http://solutionshint.com
 */

    function custom_form() {
    ?>
        <form action ="<?php echo $_SERVER['REQUEST_URI']; ?>" method ="post">
             <label for name=""> Name:</label><br>
             <input type = "text" name = "name" id = "name" placeholder = "Enter Name">
             <label for name=""> City:</label><br>
             <input type = "text" name = "city" id = "city" placeholder = "Enter City">
             <label > State:</label><br>
             <input type = "text" name = "state" id = "state"  placeholder = "Enter State">
             <label> Age:</label><br>
             <input type = "text" name = "age" id = "age"  placeholder = "Enter Age">
             <input type = "submit" name = "submit" value = "Insert">
        </form
    <?php
    }

    // add_shortcode('display', 'custom_form');

    if(isset($_POST['submit'])) {
        global $wpdb;
        $table_name ='student';
        $name = $_POST['name'];
        $city = $_POST['city'];
        $state = $_POST['state'];
        $age = $_POST['age'];

        $success = $wpdb->insert("student", array(
           "name" => $name,
           "city" => $city,
           "state" => $state,
           "age" => $age ,
        ));
        if($success) {
            echo ' Inserted successfully';
        } else {
            echo 'not';
        }
    }
?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...