I am trying to add missing records before opening a form. My example code is the following:
Code: Select all
$sql = "SELECT `telephone`
FROM `employees` WHERE `telephone` not in (SELECT telephone FROM `telephones`)
GROUP BY `telephone`";
$qry = nuRunQuery($sql);
$arr = db_fetch_array($qry);
foreach ($arr as $telephone) {
$newID = nuID();
$addsql = "INSERT INTO telephones (telephones_id, telephone, id) VALUES ('" . $newID . "', '" . $telephone . "' , 0)";
nuRunQuery($addsql);
}
I run the above code in the "Before Browse" code block of the form.
The first time I run it, it adds each missing record twice.
If I go back (to the home page), and try to open again the browse of that form, the whole application stucks, and the only thing I can do is reload the page (which forces me to relogin)
Several questions
1) Any ideas why it runs twice?
2) How can I debug it? What tools are you using?
3) How can I avoid the need to login from scratch when something goes wrong and no links work?
Thanks
Knostantinos