$valid = mysqli_query($com,"select username,email from company_profile where username = ".$uname." or email = ".$email." ");
if ($valid=="")
{echo "email n username exists";}
else
{
echo "reg success";
}
这是我的代码,我也确定它不起作用。要返回结果天气电子邮件或用户名是否存在于数据库中。
有什么办法呢。
最佳答案
mysqli_query
方法返回结果集,而不是标量。
$result = mysqli_query($com, "SELECT ...", MYSQLI_STORE_RESULT);
if ( $result->num_rows() > 0 ) {
echo "query returned at least one row";
}
代码看起来容易受到 SQL 注入(inject)的影响,我们没有看到对
mysqli_real_escape_string
的任何引用功能。我们希望看到带有绑定(bind)变量的准备好的语句,例如
if ($stmt = mysqli_prepare($com, "SELECT username,email from company_profile"
. " where username = ? OR email = ? "))
{
mysqli_stmt_bind_param($stmt, "ss", $uname, $email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_array($result))
{
}
mysqli_stmt_close($stmt);
}
关于php - 检查数据库中是否存在用户名和电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22973728/