condition if else not working???

Hi,

​I have 3 fields (field1, field2, field3), I am doing if else condition which will check field3 if not equal to the value from field1 + field2, then display an error message.

Below are the codes but it will always display error message whether the codition is true or false. Can someone please kindly help, have been trying for days.
[LEFT][SIZE=13px]Undefined variable: filename[/SIZE][/LEFT]
[LEFT][SIZE=13px]test[/SIZE][/LEFT]
$old_date_format = strtotime({field1}) ; //Y-m-d H:i:s
$new_date_format = date(‘d/m/Y H:i:s’, $old_date_format); // d/m/Y H:i:s
$result = preg_replace(’/[^a-zA-Z0-9-_.]/’,’’, $new_date_format);
$field2 = {field2};
$filename = $field2 . $result;

if ({field3} != “$filename”)
{
sc_error_message(‘test’);
}

​I tried hardcode the condition value then it works.
[LEFT][SIZE=13px]if ({field3} != “1234”)[/SIZE][/LEFT]
[LEFT][SIZE=13px]{[/SIZE][/LEFT]
[LEFT][SIZE=13px] sc_error_message(‘test’);[/SIZE][/LEFT]
[LEFT][SIZE=13px]}[/SIZE][/LEFT]

I’ll give a general answer for these kinds of things…
Find the piece of code in your generated code and put some echo statements in your generated code. Then test again…
But be aware that type comparison between different types can give you answers you dont expect (hence an error).
It looks like there is not $filename so put an echo ‘THIS IS MY FILENAME:’.$filename.’<BR>’; in your code for debugging…

Hi,

Shouldn’t…

if ({field3} != “$filename”)

Be…

if ({field3} != $filename)

Regards,

Mike

​I have been doing echo for debugging on each statement.
$filename does shows the value when I echo. It seems the condition is not checking.

​I even used a textpad and put the php code, then run it. It works. Below is the simple sample. I implement the same concept into onBeforeInsert event but don’t know why cannot works.
$string1=‘12’;
$string2=‘34’;
$test=‘1234’;
$test1=$string1.$string2;
if ($test != $test1){
echo “failed”;
}else{
echo “passed”;
​}

[LEFT][SIZE=13px]I have tried both before but does not work.[/SIZE][/LEFT]

My {field3} in my actual project is a field named filename.

If I am not wrong, I think scriptcase recognise own variable created (eg. $filename) the same as {filename}. Thus, the condition is always true.

​I just change my own variable to $filename_test and it works.

if ({filename} != $filename_test)