0
$ query_check_homework保持失敗。我相信這可能是一個非常簡單的東西,就像語法錯誤,但我一直在這工作了一個多小時,並且無法工作。你可以看看代碼,讓我知道爲什麼它會一直返回一行,即使數據庫中沒有任何內容與查詢匹配。儘管數據庫中沒有任何內容,MySQL仍保留返回行,即使數據庫中沒有任何內容與查詢匹配
這是代碼。
/*Check if homework name already exists*/
$query_check_homework = $this->db_connection->query("
SELECT
homework.homework_name
FROM classes
INNER JOIN homework On classes.class_id = homework.class_id
WHERE
homework.class_id = '".$this->class_id."' And
homework.homework_name = '".$this->homework_name."' And
classes.user_id = '".$this->user_id."'");
if ($query_check_homework == 1) {
$this->errors[] = "Sorry, You already have homework in this class with that name. Please choose a different name.";
}
else {
/*write new homework into the datebase*/
$query_new_homework = $this->db_connection->query("
INSERT INTO homework (class_id, homework_name, avaliable_points, earned_points, date) VALUES ('".$this->class_id."', '".$this->homework_name."', '".$this- >avaliable_points."', '".$this->earned_points."', '".$this->homework_date."')");
感謝。我忘了在最後添加num_rows函數。它應該看起來像'$ query_check_user_name-> num_rows == 1' – user2363217