可能重複給出:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in selectPHP MYSQL警告:請求mysql_query()預計參數1爲字符串,資源在
<?php
include 'connect.php';
include 'header.php';
$page = "signup.php";
// receive the invite code:
$code = $_POST['code'];
$sql = "SELECT codes FROM invites WHERE codes='$code'";
// check the table for matching codes
$result = mysql_query($sql);
// check if the request returned 1 or 0 rows from the database
if (mysql_query($result)) {
// end any previously defined sessions.
session_start();session_unset();session_destroy();
// start a new session
session_start();
// define the session variable.
// this allows us to check if it's set later and is required for
// the script to run properly.
$code = $_POST["code"];
mysql_query("DELETE FROM invites WHERE codes='$code'");
header('Location: '.$page);
exit;
} else {
echo "Invite invalid. Please try again later.";
echo $code;
}
include 'footer.php';
?>
我想實現的邀請系統我正在處理的網頁。然而,當試圖評估是否有包含邀請代碼的行時,我一直沒有收到任何消息或者發出警告。在這種情況下的警告,但如果我將if狀態更改爲== 1,它允許每個人無論代碼和== 0都引發不同的錯誤。
您沒有測試您的查詢是否有錯誤。請參閱mysql_query()上的PHP手冊或[參考資料:什麼是使用mysql擴展的完美代碼示例?](http://stackoverflow.com/q/6198104) –
出於好奇,您從哪裏學習此代碼? ?因爲在SO上顯示的很多mysql_query代碼不會檢查錯誤,儘管PHP手冊中的所有示例都是這樣做的。我想了解爲什麼 –
另外,你的代碼容易受到http://php.net/manual/en/security.database.sql-injection的影響。php –