gpt4 book ai didi

Php mysqli_fetch_array 不起作用

转载 作者:行者123 更新时间:2023-11-29 19:28:08 24 4
gpt4 key购买 nike

我尝试在 Android 应用程序中创建注册登录功能。我尝试使用此 Php 文件将数据从我的应用程序发送到数据库。但是,当我单击应用程序上的注册按钮时,我收到了 br/错误。看起来 mysqli_fetch_array 不起作用。有人知道如何解决这个问题吗?谢谢!

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

if($name == '' || $username == '' || $password == '' || $email == ''){
echo 'please fill all values';
}else{
require_once('dbConnect.php');
$sql = "SELECT * FROM users WHERE username='$username' OR email='$email'";
$result=mysqli_query($con,$sql);
$check = mysqli_fetch_array($result,MYSQLI_BOTH);
if(isset($check)){
echo 'username or email already exist';
}else{
$sql = "INSERT INTO users (name,username,password,email) VALUES('$name','$username','$password','$email')";
if(mysqli_query($con,$sql)){
echo 'successfully registered';
}else{
echo 'oops! Please try again!';
}
}
mysqli_close($con);
}
} else{
echo 'error';
}

dbConnect.php

<?php
define('HOST','localhost');
define('USER','username');
define('PASS','password');
define('DB','database');

$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

最佳答案

我认为你应该删除 isset 检查。无论如何,它总是会返回 true。改为进行计数检查。

if(count($check)){      
echo 'username or email already exist';
}else{
$sql = "INSERT INTO users (name,username,password,email) VALUES('$name','$username','$password','$email')";
if(mysqli_query($con,$sql)){
echo 'successfully registered';
}else{
echo 'oops! Please try again!';
}
}

关于Php mysqli_fetch_array 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41993166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com