我的一门课有问题(我相信)。在高层次上,我将一个表单发送到一个启动一个类的 php 文件。通过访问几个 it 方法,它确定一个值是否在数据库中。如果是,则返回一个布尔值。
这是我认为是问题的代码:
public function territoryCheck($numberOut)
{
$this->numberOut = $numberOut;
//Execute test
$this->checkConnect();
$stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1");
$stmt->bindParam(':param1', $this->numberOut);
$stmt->execute();
$count = $stmt->rowCount();
//Determine value of test
if($count == 0)
{
return FALSE;
}
}
public function publisherCheck($lName, $fName)
{
$this->lName = $lName;
$this->fName = $fName;
//Execute test
$this->checkConnect();
$stmt = $this->dbh->prepare("SELECT p_id FROM People WHERE lastName = :param1 AND firstName = :param2");
$stmt->bindParam(':param1', $this->lName);
$stmt->bindParam(':param2', $this->fName);
$stmt->execute();
$count = $stmt->rowCount();
//Determine value of test
if($count == FALSE)
{
return FALSE;
}
else
{
$dummyvar = $stmt->fetch();
$this->p_id = implode($dummyvar);
}
}
public function isTerritoryOut($numberOut)
{
//Execute test
$this->checkConnect();
$this->numberOut = $numberOut;
$stmt = $this->dbh->prepare("SELECT t_id FROM checkIn WHERE t_id = :param1");
$stmt->bindParam(':param1', $this->numberOut);
$stmt->execute();
$count = $stmt->rowCount();
//Determine value of test
if($count != 0)
{
return TRUE;
}
}
共有三种方法,每种方法都是一个返回真或假的测试。我正在使用 execute()、fetch() 和最后的 rowCount() 进行测试,以尝试模拟我想要的值。两者似乎都不起作用。下面是调用这些方法的代码:
//Begin tests
$checkOut->territoryCheck($numberOut);
if($checkOut == FALSE)
{
$fail = "Territory number ".$numberOut." does not exist in our records. Please enter a valid territory. For more information, navigate to About.<\ br>";
}
$checkOut->publisherCheck($lName, $fName);
if($checkOut == FALSE)
{
if($fail !== "")
$fail .= "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";
else
$fail = "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";
}
$checkOut->isTerritoryOut($numberOut);
if($checkOut === TRUE)
{
if($fail !== "")
$fail .= "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";
else
$fail = "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";
}
为清楚起见,在代码的前面将失败设置为“”。发生的情况是,当我故意创造本应失败的情况时,它会通过所有这些测试,就好像它们已经通过了一样。例如,我的数据库中只有区域编号 1-130。如果我输入 150,它基本上告诉我它存在。
我不确定发生了什么,类型转换?== 与 ===? 等。
任何帮助表示赞赏。