0

I have an if else statement, but its not working correctly. When I add it in, it only echos the first statement even if the database info doesn't match the = in the if statement, what did I do wrong?

$gameum = $db->fetch("SELECT * FROM accounts WHERE `id` = '$id'");

$status = $gameum['status'];
$gameid = $gameum['gameid'];
$search = $gameum['seraching_for'];

if($gameum['status'] = '0' ) {
$data ='<h1> Who do you want to battle against? </h1><br />
        <form action=""  method="post" id="form-pb" name="pb"   target="_self" >
        USERNAME:<input name="name" type="text" size="40" maxlength="40" />

        <input name="submit" type="submit" value="Search"/>
        </form>
        <a class="goback" href="#">Cancel</a>';
}  else { 
    $data = '<h1> Searching </h1> <br /> Searching for '.$search.'';
}

Screenshot of the database row:

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Dj Ike
  • 25
  • 1
  • 1
  • 7

4 Answers4

5
$gameum['status'] = '0' // assigns the value '0' to $gamenum['status']

($gameum['status'] == '0')  // compares the two values 
2

Your if statement should be

if($gameum['status'] == '0' ) {

and if you are looking for strict check , i suggest you do

if($gameum['status'] === '0' ) {
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

Your are Assigning$gameum['status'] to 0 , if is a conditional statement add double equal == to if condition, change

 if($gameum['status'] = '0' ) {

with

 if($gameum['status'] == '0' ) {

Single equal = Assigns the value.

Double equal == Compare value, == does not care about the data types when comparing.

Triple equal === The data types are checked to make sure the two vars/objects/whatever are using the same type.

user2092317
  • 3,226
  • 5
  • 24
  • 35
0

Change

if($gameum['status'] = '0' )  

with

if($gameum['status'] == '0' ) 

= for assigning value.

== compares the values of variables for equality

=== checks if the two variables are of the same type and have the same value.

Sonya Krishna
  • 269
  • 1
  • 11