简体   繁体   English

未定义的索引:在第29行的C:\\ xampp \\ htdocs \\ index.php中提交

[英]Undefined index: submit in C:\xampp\htdocs\index.php on line 29

Notice: Undefined index: submit in C:\\xampp\\htdocs\\index.php on line 29 注意:未定义的索引:在第29行的C:\\ xampp \\ htdocs \\ index.php中提交

<?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';
    }
}
?>

This is my code I m new to php and im devloping a plugin that will save form data into the database But I m getting the error 这是我的代码,我是php的新手,并且正在开发一个将表单数据保存到数据库中的插件,但是我遇到了错误

Notice: Undefined index: submit in C:\\xampp\\htdocs\\index.php on line 29 注意:未定义的索引:在第29行的C:\\ xampp \\ htdocs \\ index.php中提交

Try this code. 试试这个代码。 you need to use if(isset($_POST['submit'])) { 您需要使用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';
        }
    }
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 注意:未定义偏移量:1 in C:\\xampp\\htdocs\\index.php 第 5 行 - Notice: Undefined offset: 1 in C:\xampp\htdocs\index.php on line 5 第0行的C:\\ xampp \\ htdocs \\ nsoromma \\ admin \\ index.php中的未定义变量isValid - undefined variable isValid in C:\xampp\htdocs\nsoromma\admin\index.php on line 0 在C:\\ xampp \\ htdocs \\ index.php中找不到类“ Cassandra” - Class 'Cassandra' not found in C:\xampp\htdocs\index.php 注意:尝试在第5行的C:\\ xampp \\ htdocs \\ ihelploginapi \\ index.php中获取非对象的属性 - Notice: Trying to get property of non-object in C:\xampp\htdocs\ihelploginapi\index.php on line 5 解析错误:语法错误,第3行的C:\\ xampp \\ htdocs \\ yo \\ index.php中出现意外的T_STRING - Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\yo\index.php on line 3 警告:第111行的C:\\ xampp \\ htdocs \\ glasanje \\ index.php中为foreach()提供的参数无效 - Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\glasanje\index.php on line 111 警告:无法打开流:第 17 行 C:\\xampp\\htdocs\\WWW\\index.php 中的参数无效 - Warning: failed to open stream: Invalid argument in C:\xampp\htdocs\WWW\index.php on line 17 警告:在第126行的C:\\xampp\\htdocs\\bab2\\index.php 中遇到非数字值 - Warning: A non-numeric value encountered in <b>C:\xampp\htdocs\bab2\index.php</b> on line <b>126</b> 注意:未定义的索引:在线的C:\\ xampp \\ htdocs \\ cars \\ index1.php中的elegido - Notice: Undefined index: elegido in C:\xampp\htdocs\cars\index1.php on line PHP:注意:未定义的索引:第9行的C:\\ xampp \\ htdocs \\ vdab \\ cookies.php中的NameFilledIn - PHP : Notice: Undefined index: NameFilledIn in C:\xampp\htdocs\vdab\cookies.php on line 9
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM