Php 将数据更新到现有sql数据库中
我有一个应用程序,允许用户注册并将其数据保存到web服务器,但是在用户注册后访问保存的数据时,我遇到了问题。我想做的是让他们注册,然后他们可以更新更多关于他们自己的信息,这是我的注册类php文件,从应用程序中调用Php 将数据更新到现有sql数据库中,php,android,Php,Android,我有一个应用程序,允许用户注册并将其数据保存到web服务器,但是在用户注册后访问保存的数据时,我遇到了问题。我想做的是让他们注册,然后他们可以更新更多关于他们自己的信息,这是我的注册类php文件,从应用程序中调用 <?php $con = mysqli_connect("xxx", "xxx", "xxx", "xxx"); $username = $_POST["username"]; $password = $_POST["password"]; $statement =
<?php
$con = mysqli_connect("xxx", "xxx", "xxx", "xxx");
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (username, password) VALUES (?, ?)");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
print_r(json_encode($response));
?>
这可以很好地将用户名和密码保存到我的Web服务器上的新用户中。一旦他们登录,我将如何将新数据输入到他们在Web服务器中的特定条目中。有任何指针吗?您必须执行()结果和结果是您的连接准备 编辑您的代码,使其符合此要求 首先创建函数:
function saveUser($username, $password) {
$cp = $this->conn->prepare("INSERT INTO user(username, password) VALUES(?, ?)");
$cp->bind_param("ss", $username, $password);
$result = $cp->execute();
$cp->close();
if ($result) {
$cp= $this->conn->prepare("SELECT * FROM user WHERE username = ?");
$cp->bind_param("s", $username);
$cp->execute();
$user = $cp->get_result()->fetch_assoc();
$cp->close();
return $user;
} else {
return false;
}}
您的错误之一是:返回结果或$user
然后你可以像这样调用这个类或函数
$user = saveUser($name, $email, $password, $phone);
if ($user) {
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["phone"] = $user["phone"];
$response["user"]["password"] = $user["password"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
}
您的答案都是这样,不会有任何问题您必须执行()结果和结果就是您的连接准备 编辑您的代码,使其符合此要求 首先创建函数:
function saveUser($username, $password) {
$cp = $this->conn->prepare("INSERT INTO user(username, password) VALUES(?, ?)");
$cp->bind_param("ss", $username, $password);
$result = $cp->execute();
$cp->close();
if ($result) {
$cp= $this->conn->prepare("SELECT * FROM user WHERE username = ?");
$cp->bind_param("s", $username);
$cp->execute();
$user = $cp->get_result()->fetch_assoc();
$cp->close();
return $user;
} else {
return false;
}}
您的错误之一是:返回结果或$user
然后你可以像这样调用这个类或函数
$user = saveUser($name, $email, $password, $phone);
if ($user) {
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["phone"] = $user["phone"];
$response["user"]["password"] = $user["password"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
}
你的答案都是这样,没有问题看看SQL语句。引用“这是我在应用程序中调用的注册类php文件。”我没有看到任何类。密码应该是散列的,明文密码是不好的做法。这只是暂时的,而我建立了应用程序,这些链接是无价的。谢谢。看看SQL语句。引用“这是我的注册类php文件,是从应用程序中调用的。”我没有看到任何类。密码应该是散列的,明文密码是不好的做法。这只是暂时的,而我建立了应用程序,这些链接是无价的。谢谢