[英]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.