Home  >  Article  >  Backend Development  >  Notice: Trying to get property of non求大神指导下

Notice: Trying to get property of non求大神指导下

WBOY
WBOYOriginal
2016-06-23 14:09:10946browse

一个简单的登录判断下post过来的用户名username和密码pwd否相同

$user = User::getByname(username);//查询到的时候为空会报错
if($user->username == $_POST['username'] && $user->pwd== $_POST['pwd'])

if(isset($user->username))//这样没事

但我想实现上面那个登录判断下post过来的用户名username和密码pwd否相同的逻辑

请问该怎样解决,不要说@了


回复讨论(解决方案)

if($_POST) {
  $user = User::getByname($_POST['username']);
  if($user->username == $_POST['username'] && $user->pwd== $_POST['pwd'])
  ....

先判断有没有点击登录
if(isset($_POST['submit'])){
   if($user->username == $_POST['username'] && $user->pwd== $_POST['pwd']){
   
   }
}
这样就不会出用户没值报错了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn