Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP MySQLi准备的语句-检查是否已经存在_Php_Mysql - Fatal编程技术网

PHP MySQLi准备的语句-检查是否已经存在

PHP MySQLi准备的语句-检查是否已经存在,php,mysql,Php,Mysql,对于用户注册,我想确保用户名和电子邮件没有被使用。我已经在代码中的其他地方连接到$mysqli $usr = $mysqli->real_escape_string($_POST['susername']); $eml = $mysqli->real_escape_string($_POST['semail']); $stmt = $mysqli->prepare("SELECT userid FROM users WHERE username=? || email=?")

对于用户注册,我想确保用户名和电子邮件没有被使用。我已经在代码中的其他地方连接到$mysqli

$usr = $mysqli->real_escape_string($_POST['susername']);
$eml = $mysqli->real_escape_string($_POST['semail']); 

$stmt = $mysqli->prepare("SELECT userid FROM users WHERE username=? || email=?");
$stmt->bind_param("is", $usr, $eml);
$stmt->execute();
$stmt->bind_result($count);
$stmt->close();

但是,count不包含任何内容。如何检查数据库中是否已存在某些内容?

您的用户名是整数吗?您可以尝试以下代码

$stmt->bind_参数(“ss”、$usr、$eml)//ss

变更

stmt = $mysqli->prepare("SELECT userid FROM users WHERE username=? || email=?");


然后您应该使用

获取值ss是什么意思?用户名是text相同的问题-$count为空
$usr
$eml
?$usr:testuser,$eml:foo@bar.com-这是我回音时得到的。已经有一个记录具有相同的用户名和电子邮件。我使用
echo$count
-我应该使用什么?
stmt = $mysqli->prepare("SELECT count(userid) FROM users WHERE username=? || email=?");