即使数据库中没有任何内容,$query_check_homework 也会一直失败。我确信这可能是一个非常简单的问题,比如语法错误,但我已经为此工作了一个多小时并且无法使其正常工作。您能否看一下代码,让我知道为什么即使数据库中没有与查询匹配的内容,它仍然会返回一行。
这是代码。
/*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."')");