编辑书籍记录PHP

时间:2015-04-28 15:00:15

标签: php html sql

我目前正在为自己的个人教育建立一个网站,以便更好地工作,并遇到了问题。

我希望能够通过表单更新位于我数据库中的记录。

这是我到目前为止所得到的,我是否在正确的位置?

提前致谢

编辑图书表格

<?php 

include 'database_conn.php';   // make db connection

//Get the bookISBN from the request stream
 $bookISBN = $_REQUEST['bookISBN'];

//use that code in an sql statement to retrieve the details for the Book 
$sql = "SELECT bookISBN bookTitle bookYear bookPrice FROM nbc_book where     bookISBN = $bookISBN" ;

//Execute the query 
$rsAdmin = mysqli_query($conn, $sql) or die(mysqli_error($conn)); 

//get the records from the result set into variables
$adminBook = mysqli_fetch_array($rsAdmin);
$bookISBN = $adminBook['bookISBN'];
$bookTitle= $adminBook['bookTitle'];
$bookYear= $adminBook['bookYear'];
$bookPrice= $adminBook['bookPrice'];
//Display those variables in a form 
?>

<form action ='editBook.php' method = 'GET'>
<?php

echo "StudentID: $bookISBN<br />";
echo "<input type = 'hidden' name = 'bookISBN' value ='$bookISBN' />";
echo "<input type ='text' name'$bookTitle' value='$bookTitle'>";
echo "Book Title:<input type ='text' name'bookTitle'     value='$bookTitle'><br />";
echo "Book Year:<input type ='text' name'bookYear'     value='$bookYear'><br />";
echo "Book Price:<input type ='text' name'bookPrice' value='$bookPrice'><br />";
echo "<input type ='submit' value='Save'/>";


 mysqli_close($conn); 
?>
</form>

编辑图书处理

<?php

// make db connection
include 'database_conn.php';

//Get the bookISBN from the request stream
$bookISBN = $_REQUEST['bookISBN'];
$bookTitle = $_REQUEST['bookTitle'];
$bookYear = $_REQUEST['bookYear'];
$bookPrice = $_REQUEST['bookPrice'];

//construct an SQL Statement
$sql = "UPDATE nbc_books set bookTitle ='$bookTitle', bookYear ='$bookYear,     $bookPrice where bookISBN = '$bookISBN'";

//execute the SQL statment
$rsBookUpdate = mysql_query ($bookUpdateSQL);

if ($rsBookUpdate === false)    {
echo 'Updating Book failed $bookISBN, $bookTitle failed: ' . mysql_error    ();
}

?>

<!--draw link taking them back to books list-->
<a href= "Books.php">Go back to all book records</a>  

1 个答案:

答案 0 :(得分:0)

你错过引用(`):请检查你的数据库字段和查询。

$sql = "UPDATE nbc_books set bookTitle ='$bookTitle', bookYear ='$bookYear',   bookPrice = '$bookPrice' where bookISBN = '$bookISBN'";