我创建了一个方法,它应该返回一些像这样的参数:
public function registerUser($email, $first_name, $last_name, $password, $salt)
{
$sql = "insert into user_Anmeldung set email=?, first_name=?, last_name=?, user_password=?, salt=?";
$statement = $this->conn->prepare($sql);
echo $email;
echo $first_name;
echo $last_name;
echo $password;
echo $salt;
if (!$statement) {
echo "FAIL";
return;
}
else
{
$statement->bind_param("sssss", $email, $first_name, $last_name, $password, $salt);
$returnValue = $statement->execute();
}
return $returnValue;
}
这里我称之为方法:
$result = $dao->registerUser($userEmail, $userFirstName, $userLastName, $secured_password, $salt);
在这里我使用结果:
if($result)
{
$userDetails = $dao->getUserDetails($userEmail);
$returnValue["status"]="200";
$returnValue["message"]="Successfully registered new user";
$returnValue["userId"] = $userDetails["user_id"];
$returnValue["userFirstName"] = $userDetails["first_name"];
$returnValue["userLastName"] = $userDetails["last_name"];
$returnValue["userEmail"] = $userDetails["email"];
} else {
$returnValue["status"]="400";
$returnValue["message"]="Could not register user with provided information";
}
变量$email
等不是空的,但是$ resultValue似乎是空的,因为在调用一个查看结果为空的方法之后它返回true并且我无法将信息插入到我的数据库中......
答案 0 :(得分:1)
目前有几个问题对你不利,加剧了你的困惑。请参阅以下代码:
这假设您使用的是MySQLi。
$locationProvider
现在随意这样做:
public function registerUser($email, $first_name, $last_name, $password, $salt)
{
$sql = "insert into user_Anmeldung set email=?, first_name=?, last_name=?, user_password=?, salt=?";
$prepare = $this->conn->prepare($sql);
if($prepare)
{
if($prepare->bind_param("sssss", $email, $first_name, $last_name, $password, $salt))
{
if($prepare->execute())
{
return true;
}
else
{
echo 'Execute failed<br>';
}
}
else
{
echo 'Bind failed<br>';
}
}
else
{
echo 'Prepare failed<br>';
}
echo 'MySQL error: '.$prepare->error.'<br>';
return false;
}