Hello fellow sitepointers,
I wonder if you might be able to help - I think I’m being dim.
I’m trying to write a piece of code, which will result in deleting a row (a property type) from a table, so long as its id is not referenced in either of two other tables within the same db. (the other two tables represent rental and sale properties - the website is for an estate agent).
This is what I’ve concocted, but it’s not working… Any ideas guys/gals?
Thanks a mil!
Al
/////////////////////////////////////////
///////// DELETE PROPERTY TYPE //////////
/////////////////////////////////////////
if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
include $_SERVER['DOCUMENT_ROOT'] . '/admin/assets/lib/config.inc.php';
$id = mysqli_real_escape_string($link, $_POST['id']);
///Check to see if any properties currently using property type
$sql = "SELECT sales.id FROM sales WHERE typeid='$id' AND rentals.id FROM rentals WHERE typeid='$id'";
$result = mysqli_query($link, $sql);
if (isset($result))
{
$deleteerror = 'You cannot delete this property type, as Sales properties exist which are currently using it.';
include 'proptype-list.html.php';
exit();
}
else {
$sql = "DELETE FROM proptypes WHERE id='$id'";
if (!mysqli_query($link, $sql))
{
$error = 'Error deleting property type.' . mysqli_error($link);
include 'error.html.php';
exit();
}
header('Location: .');
exit();
}
}