Small IF statement problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Small IF statement problem

Post by synical21 »

I must be brain dead today as i can not get this to work. Basically i have two IF statements. I want the secound one to be executed only if the first one is true. This is probably a really simple fix but i am having trouble. Here is the code:

Code: Select all

 
if ($total > 5)
{
if ($percent < 75.0)
{
$sql=mysql_query("UPDATE users SET `banned` = '1' WHERE `id` = '$my_id'") or die( mysql_error() );
}
}
 
:banghead:
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Small IF statement problem

Post by flying_circus »

What is $total and $percent?
print $total and $percent just before this function to see what they are set to.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Small IF statement problem

Post by AbraCadaver »

Once you figure that out, you can combine this if this is as simple as it will be:

Code: Select all

if ($total > 5 && $percent < 75)
{
    $sql = mysql_query("UPDATE users SET `banned` = '1' WHERE `id` = '$my_id'") or die( mysql_error() );
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Small IF statement problem

Post by synical21 »

Thank you it is now working :)

I just got a quick question but i don't want to open another thread.

My application allows users to withdraw money, to do this a script will check the session $_SESSION['user_money'] to see how much the user has. Is this safe? Can a session value be changed easily?

If carrying a money value in a session is weak i can just make the script grab the amount of money the user has directly from the database instead of checking the session. Just would like to know what i should do :P
Post Reply