注意:未定义的属性:第13行的C:\ xampp \ htdocs \ new \ register.php中的MongoDB \ Driver \ Manager :: $ ticket

时间:2018-01-30 15:48:19

标签: php mongodb xampp database-connection

我尝试使用php创建一个简单的注册页面,mongodb作为Xampp中的数据库。 但它显示以下错误。

Notice: Undefined property: MongoDB\Driver\Manager::$ticket in C:\xampp\htdocs\new\register.php on line 13

Notice: Trying to get property 'login' of non-object in C:\xampp\htdocs\new\register.php on line 14

Fatal error: Uncaught Error: Call to a member function insert() on null in C:\xampp\htdocs\new\register.php:16 Stack trace: #0 {main} thrown in C:\xampp\htdocs\new\register.php on line 16

我无法修复错误,如果可以,请帮我解决。

PHP版本: - 7.2.1
mongodb版本: - 3.6.2

注册页面html文件: -

<html>
<head>
<title>Registration
</title>
</head>
<body>
<center><b>Registration</b></center>
<form  method="post" action="register.php">
<input type="text" name="user_name" />
<input type="password" name="user_pass" />
<input type="submit" value="Register" />
</form> 
</body>
</html>

php文件: -

<?php

if(($_POST["user_name"])&&($_POST["user_pass"]))
{
$uname=$_POST["user_name"];
$upass=$_POST["user_pass"];
$pass=md5($upass);

$con=new MongoDB/Driver/Manager("mongodb://localhost:27017");
if($con)
{
$db=$con->ticket;
$collection=$db->login;
$val=array("username=>$uname","userpassword=>$pass");
$collection->insert($val);
}
else
{
die("MongoDB is not ");
}
}
?>

0 个答案:

没有答案