gpt4 book ai didi

php - 为什么我收到错误? (PHP、MySQL)

转载 作者:行者123 更新时间:2023-11-30 01:29:51 24 4
gpt4 key购买 nike

我正在尝试获取 referral_in 的行数和referral_out存在于(作为单独的变量)。这是我的代码:

$username = $_SESSION['username'];

$connect = mysql_connect("xxxx", "xxxx", "xxxx!") or die("Couldnt Connect to Server");
mysql_select_db("xxxxx") or die("Couldnt find database");

$samecheck = mysql_query("SELECT `referral_in` FROM `users` WERE `username`=$username");
$same = mysql_num_rows($namecheck);

$leadcheck = mysql_query("SELECT `referral_out` FROM `users` WERE `username`=$username");
$leading = mysql_num_rows($namecheck);
echo "$leading / $same"

何时执行此操作,我收到此错误:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/50/8492150/html/buyarandom/member.php on line 23

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/50/8492150/html/buyarandom/member.php on line 25

最佳答案

您忘记了 $username 周围的引号

$samecheck = mysql_query("SELECT `referral_in` FROM `users` WERE `username`='".$username."'");

还请尝试转义$username,因为您的代码容易受到SQL注入(inject)

$samecheck = mysql_query("SELECT `referral_in` FROM `users` WERE `username`='".mysql_real_escape_string($username)."'");

旁注:不要使用mysql_query而是使用mysqli

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

关于php - 为什么我收到错误? (PHP、MySQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17604901/

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