在注册表页面中插入用户名时,它在phpmyadmin数据库中变为零
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在注册表页面中插入用户名时,它在phpmyadmin数据库中变为零相关的知识,希望对你有一定的参考价值。
我正在使用000webhost到我的android登录/注册应用程序,当输入数据时,所有列都填入数据库,除了用户名,它变成零,它没有给出任何错误
Register.php
<?php
$name = $_POST["name"];
$age = $_POST["age"];
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, username, age, password) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($statement, "siss", $name, $username, $age, $password);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
echo json_encode($response);
?>
的login.php
$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);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement))
$response["success"] = true;
$response["name"] = $name;
$response["age"] = $age;
$response["username"] = $username;
$response["password"] = $password;
echo json_encode($response);
?>
答案
在你对bind param的调用中,你将用户名定义为整数(i)......
mysqli_stmt_bind_param($statement, "siss", $name, $username, $age, $password);
这应该是一个s,将其保留为字符串,年龄可能是整数。
mysqli_stmt_bind_param($statement, "ssis", $name, $username, $age, $password);
以上是关于在注册表页面中插入用户名时,它在phpmyadmin数据库中变为零的主要内容,如果未能解决你的问题,请参考以下文章