0

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.

(I skipped alot of the code, which is not relevant, such as SQL connection etc)

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

this works fine, and the number gets inserted in to my SQL databse as "int(64)"

then i put the variable in to a session in a PHP script

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

then i put it down to another PHP script

$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

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.

10
  • Have you tried explicitly typecasting $Points[0] as Int? Commented Feb 1, 2013 at 21:02
  • 6
    Well you have written $Points instead of $points. Commented Feb 1, 2013 at 21:02
  • 2
    Variable names in PHP are case sensitive. You should use if ($points[0] >= 400). Commented Feb 1, 2013 at 21:03
  • 8
    This might be one of the worst titles i've ever seen on this site. Commented Feb 1, 2013 at 21:05
  • 3
    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. Commented Feb 1, 2013 at 21:13

1 Answer 1

1

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".

You need to update $_SESSION['points'] if you want the value to change.

In addition, variables are case sensitive. So in your if statement, you should be using lower case $points. You can check what mysql returns by doing var_dump($points).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.