gpt4 book ai didi

php - MYSQL查询错误-检查数据库中的用户

转载 作者:行者123 更新时间:2023-12-01 00:46:25 25 4
gpt4 key购买 nike

我试图检查用户名是否已在我的数据库中使用,但它没有回显任何内容(当我运行时为空白页),我想得到一个真或假的响应

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("data1") or die(mysql_error());


$usercheck = "john";

$sanitizeduser= filter_var($usercheck, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);

$check = mysql_query("SELECT EXISTS(SELECT 1 FROM users WHERE username = $sanitizeduser)");

echo $check;

?>

最佳答案

你已经使用了 mysqli_querymysql_ 函数

试试这个,

$link = mysqli_connect("localhost","root","","data1") or die("Error " . mysqli_error($link));
$usercheck = "john";

$sanitizeduser= filter_var($usercheck, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);

$result = $link->query("SELECT username FROM users WHERE username = '".$sanitizeduser."' ");

$row_cnt = $result->num_rows;
if($row_cnt>0){
echo "User Exists"; // echo 1;
}else{
echo "No User found"; //echo 0;
}

关于php - MYSQL查询错误-检查数据库中的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21583903/

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