$db = mysql_connect("localhost", "euicho_power", "k1nn1s0n") //open a connection to the db
or die("Unable to connect to mysql");
mysql_select_db("euicho_powermap",$db) //select the powermap database
or die("Could not select" + $dbname);
if($confirm == "confirmed") { //user confirmed they really want to delete the town
$townname = mysql_real_escape_string($townname);
$result = mysql_query("SELECT * FROM Towns WHERE name LIKE '$townname'"); //look for town in Towns
if(mysql_numrows($result) > 0) { //town was found in db
$id = mysql_result($result, 0, 'id');
$name = mysql_result($result, 0, 'name');
$lat = mysql_result($result, 0, 'lat');
$lng = mysql_result($result, 0, 'lng');
$zip = mysql_result($result, 0, 'zip');
$result = mysql_query("DELETE FROM Towns WHERE id = '$id' LIMIT 1"); //run the delete query
$result = mysql_query("SELECT * FROM Outages WHERE id = '$id'"); //look for town in Outages
if(mysql_numrows($result) > 0) {
$result = mysql_query("DELETE FROM Outages WHERE id = '$id' LIMIT 1"); //run the delete query
}
$result = mysql_query("SELECT * FROM DownNow WHERE id = '$id'"); //look for town in DownNow
if(mysql_numrows($result) > 0) {
$result = mysql_query("DELETE FROM DownNow WHERE id = '$id' LIMIT 1"); //run the delete query
}
echo("Town Deleted
\n");
echo("The town of '" . $name . "' with the following data:
");
echo("Latitude: " . $lat . "
");
echo("Longitude: " . $lng . "
");
echo("Zip Code: " . $zip . "
");
echo("...has been permanantly deleted.
\n");
echo("Return to Power Map.
\n");
}
else { //town not found in DB
echo("Error Deleting Town
\n");
echo("Error: The town '" . $townname . "' was not found in the database.
\n");
echo("Please go back and try again.
\n");
}
}
else { //confirm box not checked
echo("Error Deleting Town
\n");
echo("Error: the confirm box was not checked.
\n");
echo("Please go back and try again.
\n");
}
mysql_close($db); //close the connection to the db
?>