【发布时间】:2019-07-04 09:28: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';
}
}
?>
这是我的代码,我是 php 新手,我正在开发一个插件,可以将表单数据保存到数据库中,但我收到错误
注意:未定义索引:在第 29 行的 C:\xampp\htdocs\index.php 中提交
【问题讨论】:
-
这个元素
</form需要关闭> -
为什么表单在函数中,你从不调用函数,而是停止并启动 PHP 解释器,所以表单还是会被发送到网页?
-
关闭元素但不起作用