Not sure what is wrong with these IF statements
Posted: Sat Mar 08, 2014 10:46 pm
I'm a PHP beginner - I'm not sure what is wrong with this code. When $qotw is equal to 1, the 'cash' is increasing as its supposed to. However, when $qotw is equal to 2, the 'cash' value is still increasing and the message that should be displayed according to the 2nd IF statement is not showing up. The 'cash' value should only increase when $qotw is equal to 1.
I tried putting if($qotw == '1') instead of if(qotw = '1') but in that case only the second statement is executed and not the first (the message is displayed but the 'cash' and 'qotw' does not increase.
Please help me fix this so that BOTH statements will execute at the appropriate times. Thanks!
I tried putting if($qotw == '1') instead of if(qotw = '1') but in that case only the second statement is executed and not the first (the message is displayed but the 'cash' and 'qotw' does not increase.
Please help me fix this so that BOTH statements will execute at the appropriate times. Thanks!
Code: Select all
<?php
$con=mysqli_connect("localhost","users","password","users");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if($qotw = '1')
{
mysqli_query($con,"UPDATE users SET cash = cash + $scash
WHERE username = '". $_SESSION['username'] . "'");
mysqli_query($con,"UPDATE users SET qotw = 1 + qotw
WHERE username = '". $_SESSION['username'] . "'");
}
if($qotw = '2')
{
echo "You have already attempted this question.";
}
mysqli_close($con);
?>