即使连接正常,我的php表单也不会提交到数据库中 创建学生记录 .包装纸{ 宽度:500px; 保证金:0自动; } 创建学生记录
正确填写此表单以在Abit的数据库中创建新学生即使连接正常,我的php表单也不会提交到数据库中 创建学生记录 .包装纸{ 宽度:500px; 保证金:0自动; } 创建学生记录,php,mysql,database,forms,Php,Mysql,Database,Forms,正确填写此表单以在Abit的数据库中创建新学生 由于这两行代码,数据库更新代码将永远不会运行 首先设置$isbn\u err=“no isbn”然后测试它是否为if(empty($isbn_err)),当然,由于您给出的是一个值,它将永远不会为空,因此您将永远不会输入进行数据库访问的代码块 <?php // Include config file require_once 'config.php'; // Define variables and initialize with empt
由于这两行代码,数据库更新代码将永远不会运行 首先设置
$isbn\u err=“no isbn”
然后测试它是否为if(empty($isbn_err))
,当然,由于您给出的是一个值,它将永远不会为空,因此您将永远不会输入进行数据库访问的代码块
<?php
// Include config file
require_once 'config.php';
// Define variables and initialize with empty values
$isbn = $ISBN = $title = $Title = $pubdate = $PubDate = $pubid = $PubID = $cost = $Cost = $retail = $Retail = $category = $Category = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
if (isset($_POST["ISBN"])) {
$isbn = trim($_POST["ISBN"]);
echo "Yes, ISBN is set";
}else{
echo "N0, ISBN is not set";
}
if (isset($_POST["Title"])) {
$title = trim($_POST["Title"]);
echo "Title set";
} else
echo "Title not set";
if (isset($_POST["PubDate"])) {
$pubdate = trim ($_POST ["PubDate"]);
echo "PubD set";
} else
echo "PubD not set";
if (isset($_POST["PubID"])) {
$pubid = trim ($_POST ["PubID"]);
echo "PubID set";
} else
echo "PubID not set";
if (isset($_POST["Cost"])) {
$cost = trim ($_POST["Cost"]);
echo "Cost set";
} else
echo "Cost not set";
if (isset($_POST["Retail"])) {
$retail = trim ($_POST["Retail"]);
echo "retail set";
} else
echo "retail not set";
if (isset($_POST["Category"])) {
$category = trim($_POST ["Category"]);
echo "Category set";
} else
echo "Category not set";
$isbn_err="no isbn";
// Check input errors before inserting in database
if(empty($isbn_err) ) {
// Prepare an insert statement
$sql = "INSERT INTO books VALUES (?,?,?,?,?,?,?)";
if($stmt = $mysqli->prepare($sql)) {
// Bind variables to the prepared statement as parameters
$stmt->bind_param("issssss ", $isbn,
$title,
$pubdate,
$pubid,
$cost,
$retail,
$category);
// Set parameters
$isbn= $ISBN;
$title = $Title ;
$pubdate = $PubDate;
$pubid = $PubID ;
$cost = $Cost ;
$retail = $Retail;
$category = $Category;
// Attempt to execute the prepared statement
if($stmt->execute()) {
echo "starting query";
// Records created successfully. Redirect to landing page
header("location: index.php");
exit();
} else {
echo $stmt->error; //"Something went wrong. Please try again later.";
}
}
// Close statement
$stmt->close();
}
// Close connection
$mysqli->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Create Student Record</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
.wrapper{
width: 500px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h2>Create Student Record</h2>
</div>
<p>Fill this form correctly to create a new student in ABIIT's database.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"method="post">
<div class="form-group ">
<label>ISBN</label>
<input type="text" name="ISBN" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>TITLE</label>
<input type="text" name="Title" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>PUB Date</label>
<input type="text" name="PubDate" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>PUBID</label>
<input type="text" name="PubID" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>Cost</label>
<input type="text" name="Cost" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>retail</label>
<input type="text" name="Retail" class="form-control" value="">
<span class="help-block"></span>
</div>
<div class="form-group ">
<label>category</label>
<input type="text" name="Category" class="form-control" value="">
<span class="help-block"></span>
</div>
<input type="submit" class="btn btn-primary" value="Submit">
<a href="index.php" class="btn btn-default">Cancel</a>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
太多的代码。您需要自己更好地解决这个问题。我们不是调试器。您需要隔离问题并从中进行调试。如果你陷入困境,请清楚地解释什么东西不适合你。我建议你读一个好的问题和答案。另外,确保取下并读取.Add
ini\u集('display\u errors',1);ini_集(“日志错误”,1);错误报告(E_全部);mysqli_报告(mysqli_报告错误| mysqli_报告严格)代码>到脚本的顶部。这将强制任何mysqli\uuuu
错误生成一个异常,您可以在浏览器上看到,其他错误也可以在您的浏览器上看到。感谢您的反馈,我不知道如何启用此功能,也不知道它的作用,因为我还不熟悉我发现的语言问题我将此错误作为条件放在isset中声明谢谢
$isbn_err="no isbn";
// Check input errors before inserting in database
if(empty($isbn_err) ) {
// your db code was here