Hi!
I've been trying to make a delete function to my website but when i try to delete all i get is this msg:
Cannot delete or update a parent row: a foreign key constraint fails (`hotellromformidling`.`rombestilling`, CONSTRAINT `fk_bestilling_kunde` FOREIGN KEY (`kundeid`) REFERENCES `kunde` (`idkunde`) ON DELETE NO ACTION ON UPDATE NO ACTION)
Here is my php-page script:
<?php require_once('Connections/hotellromformidling.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if ((isset($_GET['slettID'])) && ($_GET['slettID'] != "")) {
$deleteSQL = sprintf("DELETE FROM kunde WHERE idkunde=%s",
GetSQLValueString($_GET['slettID'], "int"));
mysql_select_db($database_hotellromformidling, $hotellromformidling);
$Result1 = mysql_query($deleteSQL, $hotellromformidling) or die(mysql_error());
}
mysql_select_db($database_hotellromformidling, $hotellromformidling);
$query_kunde = "SELECT idkunde, fornavn, etternavn, adresse, postnr, telefonnr, epost, passnr FROM kunde";
$kunde = mysql_query($query_kunde, $hotellromformidling) or die(mysql_error());
$row_kunde = mysql_fetch_assoc($kunde);
$totalRows_kunde = mysql_num_rows($kunde);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table border="1">
<tr>
<td>idkunde</td>
<td>fornavn</td>
<td>etternavn</td>
<td>adresse</td>
<td>postnr</td>
<td>telefonnr</td>
<td>epost</td>
<td>passnr</td>
<td> </td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_kunde['idkunde']; ?></td>
<td><?php echo $row_kunde['fornavn']; ?></td>
<td><?php echo $row_kunde['etternavn']; ?></td>
<td><?php echo $row_kunde['adresse']; ?></td>
<td><?php echo $row_kunde['postnr']; ?></td>
<td><?php echo $row_kunde['telefonnr']; ?></td>
<td><?php echo $row_kunde['epost']; ?></td>
<td><?php echo $row_kunde['passnr']; ?></td>
<td><a href="?slettID=<?php echo $row_kunde['idkunde']; ?>">Slett</a></td>
</tr>
<?php } while ($row_kunde = mysql_fetch_assoc($kunde)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($kunde);
?>
Would really appreciate some help
