This topic is locked

if else statement

7/25/2007 4:36:33 PM
PHPRunner General questions
G
garivera author

I have gone through previous posts and pulled the code that worked, but it does not seem to work for me. My problem is the if statement is always false and it procedes to else. Can someone help me out.
Thanks
function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Save new data in another table ****
global $conn,$strTableName;

if($values["BANR_INDEX"] == "'7%%%%%'")
{

$strSQLInsert = "update masterindex set

BANR_FUND = '".$values["BANR_FUND"]."' ,

BANR_ORG = '".$values["BANR_ORG"]."' ,

BANR_PROG = '".$values["BANR_PROG"]."' ,

BANR_LOC = '".$values["BANR_LOC"]."' ,

DE = '".$values["DE"]."' ,

StartDate = '".$values["StartDate"]."' ,

EndDate = '".$values["EndDate"]."' ,

OH = '".$values["OH"]."' ,

FY_YEAR = '".$values["FY_YEAR"]."' ,

Comments = 'Not Completed'

where BANR_INDEX=".$values["BANR_INDEX"];

db_exec($strSQLInsert,$conn);
//** Insert a record into another table ****
$strSQLInsert = "insert into masterindex (DE, Comments) values (NULL, 'Available')";

db_exec($strSQLInsert,$conn);
}
else

{

}
return true;
// return true if you like to proceed with adding new record

// return false in other case
}

Sergey Kornilov admin 7/26/2007

It looks like you have extra quotes in if condition. Try the following:

if($values["BANR_INDEX"]== "7%%%%%")

G
garivera author 7/26/2007

It looks like you have extra quotes in if condition. Try the following:


It did not work,
I dont get any errors, but it is still bypassing the if and going streight to the else. Any other suggestions.
Gabe

Sergey Kornilov admin 7/26/2007

Gabe,
print the value of $values["BANR_INDEX"] variable on the Web page to make sure you are not comparing apples to oranges.

echo "BANR_INDEX: " . $values["BANR_INDEX"];
G
garivera author 7/26/2007

Gabe,

print the value of $values["BANR_INDEX"] variable on the Web page to make sure you are not comparing apples to oranges.

echo "BANR_INDEX: " . $values["BANR_INDEX"];


I did the echo and I was getting the value I was expecting, but I played with the code to the following and it seemed to work. Im not sure if that was the best way to do it, but it works.
if($values["BANR_INDEX"]=$values["BANR_INDEX"])
not sure why the one equals sign made the difference.
Gabe

Sergey Kornilov admin 7/26/2007

Gabe,
this code is not correct.
Instead of comparing two values you assigning a value to the variable.
If you like me to take a closer look post your app to Demo Account and send the URL to support@xlinesoft.com.