doubo7131
2019-07-04 09:28
浏览 214
已采纳

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

Notice: Undefined index: submit in C:\xampp\htdocs\index.php on line 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';
    }
}
?>

This is my code I m new to php and i m devloping a plugin that will save form data into the database But I m getting the error

Notice: Undefined index: submit in C:\xampp\htdocs\index.php on line 29

图片转代码服务由CSDN问答提供 功能建议

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

 &lt;?php 
 / ** 
 *插件名称:表格插入数据库
 *插件URI:http://solutionshint.com 
 *描述:只需将数据插入 自定义表单
 *版本:1.0 
 *作者:SolutionsHint 
 *作者URI:http://solutionshint.com 
 * / 
 
函数custom_form(){
?&gt; 
&lt;表单操作 =“&lt;?php echo $ _SERVER ['REQUEST_URI'];?&gt;”  method =“post”&gt; 
&lt; label for name =“”&gt; 姓名:&lt; / label&gt;&lt; br&gt; 
&lt; input type =“text”name =“name”id =“name”placeholder =“Enter Name”&gt; 
&lt; label for name =“”&gt  ; 城市:&lt; / label&gt;&lt; br&gt; 
&lt; input type =“text”name =“city”id =“city”placeholder =“Enter City”&gt; 
&lt; label&gt; 州:&lt; / label&gt;&lt; br&gt; 
&lt; input type =“text”name =“state”id =“state”placeholder =“Enter State”&gt; 
&lt; label&gt; 年龄:&lt; / label&gt;&lt; br&gt; 
&lt; input type =“text”name =“age”id =“age”占位符=“输入年龄”&gt; 
&lt; input type =“submit”name  =“submit”value =“Insert”&gt; 
&lt; / form 
&lt;?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-&gt; insert(“student”,array(
“name”=&gt;  ; $ name,
“city”=&gt; $ city,
“state”=&gt; $ state,
“age”=&gt; $ age,
)); 
 if($ success){  
 echo'Inserted successfully'; 
} else {
 echo'not'; 
} 
} 
?&gt; 
   
 
 

这是 我的代码我刚开始使用php和im开发一个将表单数据保存到数据库中的插件但是我收到了错误

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongxiongshi9952 2019-07-04 10:03
    已采纳

    Try this code. you need to use 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';
            }
        }
    ?>
    
    点赞 评论

相关推荐 更多相似问题