Jump to content

Wierd if else problem


elabuwa

Recommended Posts

Hi guys,

 

this probably aint wierd for you, but it seems like php is playin up to me. may b i missed something. so i'm kinda needing another set or may more sets of eyes. lol.

 

this is the code.

 

while($row = mysql_fetch_array($result)){

$debit = $row['debit'];

$credit = $row['credit'];

$acnum = $row['acnum'];

$query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";

$res = mysql_query($query1);

$balancenum=mysql_num_rows($res);

while($row1 = mysql_fetch_array($res)){

$cbal = $row1['cbal'];

}

If (is_numeric($debit)){

$actype = substr($acnum,0,1);

settype($actype, "integer");

echo $actype;

echo "<br>";

echo gettype($actype);

echo "<br>";

If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == 8){

$cbal = $cbal - $debit;

$sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo "2" . $sql2;

echo "<br>";

mysql_query($sql2);

} else {

$cbal = $cbal + $debit;

$sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo "2". $sql2;

echo "<br>";

mysql_query($sql2);

}

}

If (is_numeric($credit)){

$actype = substr($acnum,0,1);

settype($actype, "integer");

echo $actype;

echo "<br>";

echo gettype($actype);

echo "<br>";

If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == 8){

$cbal = $cbal + $credit;

$sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo $sql;

echo "<br>";

mysql_query($sql);

} else {

$cbal = $cbal - $credit;

$sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo $sql;

echo "<br>";

mysql_query($sql);

}

}

}

 

The wierd thing about the above code is the entire if statement is carried out including the else part.

For example if $actype == 5 it does the stuff that is to be done when the value is 5, AND the stuff to be done in the ELSE section is also carried out. :wtf: :wtf: :wtf: :wtf:

 

can you pleaase help me out.  :shrug: :shrug: :shrug: :shrug:im kinda stuck. lol.  :D

Link to comment
https://forums.phpfreaks.com/topic/184589-wierd-if-else-problem/
Share on other sites

Hi mate,

pleased use


tags,

 

while($row = mysql_fetch_array($result)){
   $debit = $row['debit'];
   $credit = $row['credit'];
   $acnum = $row['acnum'];
   $query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";
   $res = mysql_query($query1);
   $balancenum=mysql_num_rows($res);
   while($row1 = mysql_fetch_array($res)){
      $cbal = $row1['cbal'];
   }
   If (is_numeric($debit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == {
         $cbal = $cbal - $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2" . $sql2;
         echo "<br>";
         mysql_query($sql2);
      } else {
         $cbal = $cbal + $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2". $sql2;
                  echo "<br>";
         mysql_query($sql2);
      }
   }
   If (is_numeric($credit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == {
         $cbal = $cbal + $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
         echo "<br>";
         mysql_query($sql);
      } else {
         $cbal = $cbal - $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
                  echo "<br>";
         mysql_query($sql);
      }
   }
}

Odd. Can't see a reason why it would. Is it definitely doing both? Try adding in some random echo's to check for sure..

 

while($row = mysql_fetch_array($result)){
   $debit = $row['debit'];
   $credit = $row['credit'];
   $acnum = $row['acnum'];
   $query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";
   $res = mysql_query($query1);
   $balancenum=mysql_num_rows($res);
   while($row1 = mysql_fetch_array($res)){
      $cbal = $row1['cbal'];
   }
   If (is_numeric($debit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype ==  {
         echo 'foo';
         $cbal = $cbal - $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2" . $sql2;
         echo "<br>";
         mysql_query($sql2);
      } else {
         echo 'bar';
         $cbal = $cbal + $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2". $sql2;
                  echo "<br>";
         mysql_query($sql2);
      }
   }
   If (is_numeric($credit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype ==  {
         $cbal = $cbal + $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
         echo "<br>";
         mysql_query($sql);
      } else {
         $cbal = $cbal - $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
                  echo "<br>";
         mysql_query($sql);
      }
   }
}

 

(note the 'foo' / 'bar' echos)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.