这是我用来检查用户名可用性的编码。我认为getMatchedCount()
方法/函数有问题。这是因为,我在那一行不断出现错误,错误是:
'Fatal error: Uncaught Error: Call to a member function getMatchedCount() on null in C:\xampp\htdocs\project\OrgChart-master\OrgChart-master\memberForgotPassword.php:35 Stack trace: #0 {main} thrown in C:\xampp\htdocs\project\OrgChart-master\OrgChart-master\memberForgotPassword.php on line 35'
如何解决此问题?还是有其他方法可以从mongodb
数据库中检查用户名的可用性?
预先,谢谢您对我的帮助。 :)
if(isset($_POST['registration']))
{
$registration = ($_POST['registration']);
if(!empty($registration))
{
//$cursor = $collection->find(array("registration" => $registration));
//$result = $cursor->count();
$result = $db->collection1->findOne(array("registration"=>$registration));
if($result->getMatchedCount()==0)
{
echo "Username Available";
}
else
{
echo "Please Enter The Correct Username";
}
}
}