Jump to content

if statement inside a function problem


GD77

Recommended Posts

Hello, I ve the following code and the if is always returning returning true:

 

function db_LA() {

$this->u_tst=".....";

$qry_1=mysql_query("SELECT COUNT(`yyy`) FROM `tbl` WHERE `id_tst`='".$this->u_tst."' ");

$fetch_1=mysql_result($qry_1,0,0);

 

if($fetch_1==0) {

$qry_2=mysql_query("INSERT INTO `tbl` (...) VALUES (...) or die(mysql_error());

}

if($fetch_1>0 && $fetch_1<4) {

$qry_2_Update=mysql_query("UPDATE `tbl` SET `att` = `att` +1 WHERE `id`='".$this->u_tst."');

}

}

//if($fetch_1>0 && $fetch_1<4) { <---- this is being exsecuted even if the value was above 4

Link to comment
https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/
Share on other sites

I don't see any problem except those syntax issues in query lines. Try to echo variable $fetch_1 before if loops.

 

$qry_2=mysql_query("INSERT INTO `tbl` (...) VALUES (...)") or die(mysql_error());

 

 

$qry_2_Update=mysql_query("UPDATE `tbl` SET `att` = `att` +1 WHERE `id`='".$this->u_tst."'");

$fetch_1>0 && $fetch_1<4 <-- means values betwen 0 and 4 1,2,3... f the value is 5 or 6 the code should not be executed so why is it?

 

As was stated, it's executing because the value is not actually > 4, as you believe.

 

Try adding this line to your code, and you'll see something other than you expect.

 

 

      $fetch_1=mysql_result($qry_1,0,0);

      echo $fetch_1;

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.