2017-02-15 97 views
-1

IM上的登录工作制/注册到我的网站 我这个小问题,即应用程序犯规reconize如果用户已经registred,或者如果它不是注册检测registred用户PHP的

<?php 
// including $conn the connextion between database and the app from the dbh.php 
include '../dbh.php'; 

$first = $_POST['first']; 
$last = $_POST['last']; 
$userid = $_POST['userid']; 
$email = $_POST['email']; 
$pwd = $_POST['pwd']; 

    $sql = "SELECT * from user WHERE userid=".$userid; 
    $results = mysqli_query($conn , $sql); 
    $useridcheck = $results->num_rows; 

//if there is a registred username in the database same as $userid 
    if($useridcheck > 0) 
    { 

     header('location: ../signupform.php?error=username'); 
     exit(); 
    } 
// there is no match to $userid in the database so go ahaid and register this new user 
    else{ 
     $sql ="INSERT INTO user(first,last,userid,email,pwd) 
     VALUES('$first','$last','$userid','$email','$pwd')"; 
     $results = mysqli_query($conn , $sql); 
     header('location: ../index.php'); 

    } 

问题出在if ($useridcheck > 0) 当运营商设置为= 1它运行第一个块,如果它设置为> 0它运行第二个块。我不知道什么是问题,但我猜测它必须与变量$useridcheck = $results->num_rows

+0

'$ useridcheck = mysqli_num_rows($ results);'并检查 –

+0

@Anant为什么? '$ results-> num_rows;'是有效的。好吧,它是面向过程的混合对象,但它仍然有效。 –

+0

其他的东西导致你的代码中断,你需要检查错误的原因。 –

回答

0

尝试替换: $ useridcheck = $ results-> num_rows;使用: $ useridcheck = mysqli_num_rows($ results);

+0

我不明白这会如何改变。 –

+0

不行,它是一样的 –