我有一个问题,所以如果用户偶然搜索并且它的代码不再激活,我想这样做。这样我就做了一个简单的代码:
$loginu = $_SESSION['login'];
$query = "SELECT `usrlogin`,`idcode` FROM `aktywacja` WHERE idcode = $numer AND usrlogin = $loginu ";
$result2 = mysql_query($query);
echo mysql_error();
if (mysql_num_rows($result2) == 0) {
not found
}
else {
found
}
并使我因以下错误而崩溃
Unknown column 'Kamil' in 'where clause' Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\kod.php on line 56 Where in this case I made a mistake?
请帮忙,
问候。
最佳答案
如果这些字符串不是整数,请确保用引号引起来:
WHERE idcode = $numer AND usrlogin = '$loginu'
并确保此变量 $numer
确实已定义,因为在您的问题中没有定义它。
强制性说明:
Please, don't use
mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
下面是在 mysqli 中使用准备好的语句时的样子:
$loginu = $_SESSION['login'];
$numer = // make sure this is defined!
$db = new mysqli('localhost', 'username', 'password', 'database_name');
$query = "SELECT `usrlogin`,`idcode` FROM `aktywacja` WHERE idcode = ? AND usrlogin = ?";
$select = $db->prepare($query);
// binding them
$select->bind_param('is', $numer, $loginu);
$select->execute();
if($select->num_rows > 0) {
// found
} else {
// not found
}
关于PHP 不检查 MySQL 数据库中是否已有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26816186/