简体   繁体   English

将MySQL中的值与PHP中的int进行比较不起作用

[英]Comparing value from MySQL to an int in PHP doesn't work

I am attempting to make my own website, from scratch, for a school project. 我正尝试从头开始为学校项目创建自己的网站。 It is going very well, and I got really far, but I encountered an issue, when comparing a variable to a number in a PHP script. 一切进展顺利,我走得很远,但是在将变量与PHP脚本中的数字进行比较时遇到了一个问题。

(I skipped alot of the code, which is not relevant, such as SQL connection etc) (我跳过了很多不相关的代码,例如SQL连接等)

$SQL = "INSERT INTO members (points) VALUES ('800')";

this works fine, and the number gets inserted in to my SQL databse as "int(64)" 这工作正常,并且该数字作为“ int(64)”插入到我的SQL数据库中

then i put the variable in to a session in a PHP script 然后我将变量放入PHP脚本的会话中

$_SESSION['points'] = $points[0];

then i put it down to another PHP script 然后我把它放到另一个PHP脚本中

$SQL = mysql_query("SELECT points FROM members WHERE username = $uname");
$points = mysql_fetch_row($SQL);

still fine, when I check $points[0] it is still 800 仍然可以,当我检查$ points [0]时仍然是800

but I can't compare it in a statement such as this 但我无法在这样的语句中进行比较

if ($Points[0] >= 400)
{echo "took it";
}
else {echo "didnt take it";
}

Any idea of what could be wrong? 有什么问题的想法吗? It is bigger, but the variable gets threated as if its lower or empty. 它较大,但是变量受到威胁的程度似乎较小或为空。

I'm taking a guess here, but I think you intend to compare $_SESSION['points'] when you say "then i put it down to another PHP script" . 我在这里猜测,但是当您说“然后我将其放到另一个PHP脚本中”时,我想您打算比较$_SESSION['points']

You need to update $_SESSION['points'] if you want the value to change. 如果您想更改值,则需要更新$_SESSION['points']

In addition, variables are case sensitive. 此外,变量区分大小写。 So in your if statement, you should be using lower case $points . 因此,在if语句中,应使用小写的$points You can check what mysql returns by doing var_dump($points) . 您可以通过执行var_dump($points)来检查mysql返回的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM