This topic is locked

Simple email on tinyint change

8/29/2006 9:56:15 AM
PHPRunner General questions
G
giles author

Hi,

I'm trying to send simple notification emails whenever a User changes a "tinyint" status field (Suspended) in a particular table (_tester)
I am using a BeforeRecordUpdate event on the edit page and trying to trigger the email to be sent when the User changes the status field via a checkbox and then clicks on save.
Here's the code I'm using...
function BeforeEdit(&$values, $where)

{
//** Custom code ****

// put your custom code here

global $conn;

$str = "select Suspended from _tester where ".$where;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

echo $data["Suspended"];

echo $values["Suspended"];

if (strcmp("'".$data["Suspended"]."'",$values["Suspended"])!=0)

{

echo "Send the emails";

}

return true;
// return true if you like to proceed with editing this record

// return false in other case
}
The echos for $data and $values show the correct states of the data base and edit form values for the status field. Only trouble is the "Send the emails" is ALWAYS triggered. Fair enough that I get:

01Send the emails

10Send the emails

But why:

11Send the emails

00Send the emails ????? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=3294&image=1&table=forumtopics' class='bbc_emoticon' alt=':(' />
Can anyone see what's wrong here. Or suggest a better way...
Giles
P.S. Great work on the Visual Editor in 3.1

F
frocco 8/29/2006

Did you try and remove the "'" from $data["Suspended"] in the strcmp?
Frank

Hi,

I'm trying to send simple notification emails whenever a User changes a "tinyint" status field (Suspended) in a particular table (_tester)
I am using a BeforeRecordUpdate event on the edit page and trying to trigger the email to be sent when the User changes the status field via a checkbox and then clicks on save.
Here's the code I'm using...
function BeforeEdit(&$values, $where)

{
//** Custom code ****

// put your custom code here

global $conn;

$str = "select Suspended from _tester where ".$where;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

echo $data["Suspended"];

echo $values["Suspended"];

if (strcmp("'".$data["Suspended"]."'",$values["Suspended"])!=0)

{

echo "Send the emails";

}

return true;
// return true if you like to proceed with editing this record

// return false in other case
}
The echos for $data and $values show the correct states of the data base and edit form values for the status field. Only trouble is the "Send the emails" is ALWAYS triggered. Fair enough that I get:

01Send the emails

10Send the emails

But why:

11Send the emails

00Send the emails ????? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=10745&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
Can anyone see what's wrong here. Or suggest a better way...
Giles
P.S. Great work on the Visual Editor in 3.1

G
giles author 8/29/2006

Thank Frank,
Removal of the "'" worked perfectly.
Giles