如何使用PHP获取在数据库中创建的用户id?

如何使用PHP获取在数据库中创建的用户id?,php,android,sql,login,userid,Php,Android,Sql,Login,Userid,我尝试使用会话或不使用会话。也许我在使用会话时遇到了问题。 在phpMyAdmin中,我使用的是userid int(11)自动增量 使用POST方法创建的所有内容都有效 <?php session_start(); $con = mysqli_connect("mysql11.000webhost.com", "a7083778_user", "abcd12734", "a70830778_data"); $username = $_POST["username"];

我尝试使用会话或不使用会话。也许我在使用会话时遇到了问题。 在phpMyAdmin中,我使用的是
userid int(11)自动增量

使用POST方法创建的所有内容都有效

<?php
session_start();    
$con = mysqli_connect("mysql11.000webhost.com", "a7083778_user",      "abcd12734", "a70830778_data");

$username = $_POST["username"];
$password = $_POST["password"];

$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $age ,$username, $password, $userPoints);

$response = array();
$response["success"] = false;  
$_SESSION["userid"] = $userID;
while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;
$response["userID"] = $_SESSiON["userid"]; 
    $response["name"] = $name;
    $response["age"] = $age;
    $response["username"] = $username;
    $response["password"] = $password;
$response["userPoints"] = $userPoints;
}

echo json_encode($response);
 ?>

请试试这个,我想它对你有用


您想要一个唯一的id吗?这个问题相当复杂unclear@Shubhanksori这是我的第一个问题,是的,我需要唯一的id(在数据库中创建,我可以使用自动增量)来为每个用户在Android应用程序中创建唯一的二维码。请注意,未加密/明文密码被认为是不安全的做法。您应该使用适当的强算法对它们进行散列。谢谢您的评论,但我有一个致命错误:如果您输入了错误的用户名和密码,请在第9Sir行的/home/a7083098/public_html/Login.php中对非对象调用成员函数fetch_assoc(),然后会出现此错误。因为如果没有从数据库获取任何数据,则$result->fetch_assoc()将显示此错误。sori但这不起作用:(,我甚至无法登录。这是一个Android应用程序。您输入的用户名和密码是否存在于数据库中,请检查先生