function insert_new_user($username, $password)
{
# checking username is already taken
if (username_exists($username))
return false;
# insert new user info
global $pdo;
$stmt = $pdo->pprepare('
INSERT INTO users
(username, password)
values (:username, :password)');
$stmt->execute( array(':username' => $username, ':password' => md5($password)) );
if ($pdo->lastInsertId())
return true;
else
return false;
}
当我尝试从mysql db检查用户存在时,我从这个php代码得到不确定的错误。我没有发现错误。如果我在编码方面做错了,请帮助我。
答案 0 :(得分:1)
function insert_new_user($username, $password)
{
# checking username is already taken
if (username_exists($username))
return false;
# insert new user info
global $pdo;
$stmt = $pdo->prepare('
INSERT INTO users
(username, password)
values (:username, :password)');
$stmt->execute( array(':username' => $username, ':password' => md5($password)) );
if ($pdo->lastInsertId())
return true;
else
return false;
}
试试这个。我想你准备好了。