【发布时间】:2018-09-09 19:08:07
【问题描述】:
程序应该使用表单来更新数据库
我删除了更新表的查询,然后页面出现了,我有一个预设检查器,当我取出查询以更新页面显示,当我添加它时,我被重定向到页面
这是我认为有错误的代码
$sql = "UPDATE books SET ISBN=?,Title=?,PubDate=?,PubID=?,Cost = ?, Retail = ?, Category = ? WHERE books.ISBN='$isbn'";
if($stmt = $mysqli->prepare($sql)){
$stmt->bind_param("issiiis", $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();
}
另一方面,这是从数据库获取信息的查询
// Check existence of student_ID parameter before processing further
if(isset($_GET["ISBN"]) && !empty(trim($_GET["ISBN"])))
{
// Get URL parameter
$id = trim($_GET["ISBN"]);
// Prepare a select statement
$sql = "SELECT * FROM books WHERE ISBN = ?";
if($stmt = $mysqli->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bind_param("s", $param_id);
// Set parameters
$param_id = $isbn;
// Attempt to execute the prepared statement
if($stmt->execute()){
$result = $stmt->get_result();
if($result->num_rows == 1){
/* Fetch result row as an associative array. Since the result set
contains only one row, we don't need to use while loop */
$row = $result->fetch_array(MYSQLI_ASSOC);
// Retrieve individual field value
$ISBN = $row["ISBN"];
$Title= $row["Title"];
$PubDate = $row["PubDate"];
$PubID = $row["PubID"];
$Cost = $row["Cost"];
$Retail = $row["Retail"];
$Category = $row["Category"];
}
else
{
// URL doesn't contain valid student_ID. Redirect to error page
header("location: error.php");
exit();
}
}
else
{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
$stmt->close();
// Close connection
$mysqli->close();
} else{
// URL doesn't contain student_ID parameter. Redirect to error page
header("location: error.php");
exit();
}
我为代码量和我的无知提前道歉,但这非常重要
【问题讨论】:
-
这篇文章很长。
-
您需要简化问题。这里的代码太多了。见stackoverflow.com/help/mcve
-
完成了,我有两个问题我认为已经发布了问题
标签: php mysql sql database wamp