目前尚不清楚,但我相信你應該移動$id = $_POST['id']
您if
聲明
內的代碼應該是:
<?PHP
include "configdb.php";
if (isset($_POST['id']))
{
$id = $_POST['id'];
$sql = "SELECT * FROM `booklist` WHERE `id` = '$id'";
$res = mysqli_query($connect, $sql) or die("Could not update".mysql_error());
$row = mysqli_fetch_row($res);
$id = $row[0];
$title = $row[1];
$author = $row[2];
$ISBN = $row[3];
$category = $row[4];
$image_upload = $row[5];
$image_upload2 = $row[6];
}
?>
EXTRA信息
如果我認爲這個問題是有關從書單讓書籍ID,然後運行在數據庫返回的結果,然後查詢一個更好的代碼會是這樣的:
<?PHP
include "configdb.php";
if (isset($_POST['id']))
{
$id = $_POST['id'];
$sql = mysqli_query($connect, "SELECT * FROM booklist WHERE id = $id") or die("Could not update".mysql_error());
$rows = mysqli_num_rows($sql); // get the number of returning rows (0 means no query match found, > 0 means a query match found)
if($rows > 0)
{
while($i = mysqli_fetch_assoc($sql))
{
$book_id = $sql[0];
$book_title = $sql[1];
$author = $sql[2];
$ISBN = $sql[3];
$category = $sql[4];
$image_upload = $sql[5];
$image_upload2 = $sql[6];
// the rest of your code and what you want to do with the result....
}
}
eles // no results found message
{
echo 'Sorry, no results found.';
} // end of else
}
?>
同時請注意,您可以使用列名,而不是$sql[0], $sql[1], $sql[3]
所以如果你的第一個表列有book_id
一個名字,那麼它可以
$book_id = $sql['book_id'];
而不是$book_id = $sql[0];
。當你在你的代碼中工作時,這很容易處理,所以你不必回頭查看你的數據庫來檢查列的索引。當你更新你的代碼或與他人分享時,它也會幫助你很多。
您的'$ _POST'數組沒有索引爲'id'的元素。通常你應該首先檢查if(isset($ _ POST ['id']))$ id = intval($ _ POST ['id']); else $ id = false;'和後面的'if($ id)..'並閱讀SQL注入 – Cheery 2014-10-05 00:13:45