對不起,這可能是一個非常愚蠢的問題,但在人們將查看的頁面上運行此代碼是否安全,還是應該將其封裝到函數中並調用它?在人們將要訪問的頁面上運行此查詢是否安全?
$stmt = $db->prep_stmt("select * from .... where userid = ? and username = ?");
/* Binding 2 parameters. */
$stmt->bind_param("is", $userid, $username);
/* Binding 2 result. */
$stmt->bind_result($isbn, $title, $author, $coef, $bookid);
/* Executing the statement */
$stmt->execute() or die ("Could not execute statement");
/*
* Making PHP buffer the whole result,
* not recommended if there is a blob or
* text field as PHP eats loads of memory
*/
$stmt->store_result();
while ($stmt->fetch()) {
/*
* Here you can use the variables $isbn, $title, $author, $coef, $bookid,
* which contatin the data for 1 row.
*/
print "<tr>".
"<td>".$isbn."</td>".
"<td>".$title."</td>".
"<td>".$author."</td>".
"</tr><tr><td>";
}
進行消毒處理嗯,這實際上並不是我的代碼。我只是從準備好的語句的教程頁面複製它。我只是好奇,如果可以的話,如果我在我的index.php中有這樣的代碼,並且使用該網站的人在index.php – mcbeav 2010-12-17 04:43:09
上,但是感謝您的好評,我非常感謝幫助 – mcbeav 2010-12-17 04:43:32