如果用户的信息(登录信息)与存储在数据库中的信息相匹配,我想在php设备上生成一个php文件返回true或false。
到目前为止,我已经编写了以下代码:
<?php
require "init.php";
if($connection){
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($connection,"SELECT * FROM `admin` WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement,"ss",$username,$password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_close($connection);
}
答案 0 :(得分:0)
简单的mysqli_stmt_execute返回一个布尔值只打印结果,或者你可以制作一个json。
<?php
require "init.php";
require "init.php";
if($connection){
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($connection,"SELECT * FROM `admin` WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement,"ss",$username,$password);
if(mysqli_stmt_execute($statement)){
echo "true";
}else {
echo "false";
}
mysqli_stmt_store_result($statement);
mysqli_close($connection);
}
答案 1 :(得分:0)
要返回一个json,你必须创建一个关联数组并将其编码为json。
<?php
require "init.php";
require "init.php";
if($connection){
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($connection,"SELECT * FROM `admin` WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement,"ss",$username,$password);
if(mysqli_stmt_execute($statement)){
$response=array('response'=>true);
}else {
$response=array('response'=>false);
}
echo json_encode($response);
mysqli_stmt_store_result($statement);
mysqli_close($connection);
}