我正在创建一个使用HTML / PHP和mySQL应用CRUD功能的表单。我可以删除,阅读和更新,但是无法创建新记录。以下是我的数据库结构,索引页面和创建页面。任何指导表示赞赏。我没有包含配置文件,因为我认为没有必要。数据库名称谢谢!
确切错误
注意:未定义的索引:在第30行的C:\ xampp \ htdocs \ Update \ create.php中排名
create.php
// Include config file
require_once "config.php";
// Define variables and initialize with empty values
$nickname = $lastsubmission = $rank = "";
$nickname_err = $lastsubmission_err = $rank_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate name
$input_nickname = trim($_POST["nickname"]);
if(empty($input_nickname)){
$nickname_err = "Please enter a name.";
} elseif(!filter_var($input_nickname, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z\s]+$/")))){
$nickname_err = "Please enter a valid name.";
} else{
$nickname = $input_nickname;
}
// Validate address
$input_lastsubmission = trim($_POST["lastsubmission"]);
if(empty($input_lastsubmission)){
$lsstsubmission_err = "Please enter an address.";
} else{
$lastsubmission = $input_lastsubmission;
}
// Validate salary
$input_rank = trim($_POST["rank"]);
if(empty($input_rank)){
$rank_err = "Please enter the salary amount.";
} elseif(!ctype_digit($input_rank)){
$rank_err = "Please enter a positive integer value.";
} else{
$rank = $input_rank;
}
答案 0 :(得分:1)
您的昵称元素需要 name 属性。可能是复制/粘贴错误?
Same适用于所有其他HTML输入元素。
将nickname="nickname"
更改为name="nickname"
。
<input type="text" name="nickname" class="form-control" value="<?php echo $nickname; ?>">
答案 1 :(得分:0)
这是因为在将$ param_nickname与mysqli_stmt_bind_param绑定后分配了$ param_nickname
//First Set parameters
$param_nickname = $nickname;
$param_lastsubmission = $lastsubmission;
$param_rank = $rank;
//Then Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "sss", $param_nickname,
$param_lastsubmission, $param_rank);
应该可以解决问题