Hi,
I'm trying to enforce refrential integerity using PHP rather than foreign keys because I just can't get the foreign keys to work in mySQL.
However, I get a funny error ("Parse error: parse error, unexpected $end in c:\inetpub\wwwroot\arms_data_model\deletes\confirm_control_delete.php on line 230") on a row that contains no code - one that occurs after all the code (PHP and HTML) is finished. This makes me think that I forgot a bracket or a semicolon somewhere.
Below is the code that I use to check whether I can delete a record from table arms_control. It should not be deleted if a screen or a report is linked to it and I check that by doing a query and testing whether the number of rows returned are greater than 0.
if ((isset($_POST["MM_delete"])) && ($_POST["MM_delete"] == "delete_control")) {
if ($totalRows_control_screens > 0 Or $totalRows_control_reports > 0) {
echo "You can't delete this control because it's linked to the following screen(s):";
do {
echo $row_control_screens['screen_name'];
}
while ($row_control_screens = mysql_fetch_assoc($control_screens));
echo "\nOr it is linked to the following reports:";
do {
echo $row_control_reports['report_name'];
}
while ($row_control_reports = mysql_fetch_assoc($report_screens));
}
else {
$deleteSQL = sprintf("DELETE FROM arms_control WHERE control_id=%s",
GetSQLValueString($_POST['control_id'], "int"));
mysql_select_db($database_arms_data_model, $arms_data_model);
$Result1 = mysql_query($deleteSQL, $arms_data_model) or die(mysql_error());
$deleteGoTo = "delete_successful.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $deleteGoTo));
}
}
Can anyone see a flaw in this logic or is there perhaps a better way of doing it?
Thanks
Hanlie