-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete_place.php
65 lines (64 loc) · 2.33 KB
/
delete_place.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Delete place</title>
</head>
<body>
<?php
include_once 'config.php';
$id = NULL;
$pass1 = NULL;
//Check if the user name and password have been set.
if (isset($_GET["id"]) && isset($_GET["pass"]) ) { //if 0
$id = $_GET["id"];
$pass1 = $_GET["pass"];
//Check if they are correct.
try {
$dbh = new PDO('mysql:dbname='.$dbname.';host='.$host.';port='.$port, $user, $pass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT * FROM `user` WHERE `id`=:id AND `pass`=:pass");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':pass', $pass1);
$stmt->execute();
//If at least one row has been returned, then the id and the pass are correct.
if($stmt->fetch()) { //if 1
//Remove the desired place.
if (isset($_GET["title"]) && isset($_GET["lon"]) && isset($_GET["lat"])) { //if 2
$title = $_GET["title"];
$lon = $_GET["lon"];
$lat = $_GET["lat"];
$stmt = $dbh->prepare("DELETE FROM `place` WHERE `ownerid`=:id AND `title`=:title AND `lon`=:lon AND `lat`=:lat");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':lon', $lon);
$stmt->bindParam(':lat', $lat);
$stmt->execute();
echo "Delete OK";
?>
<form method="POST" action="insert_place.php" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="hidden" name="pass" value="<?php echo $pass1; ?>" />
<input type="submit" name="submit" value="Go back"/>
</form>
<?php
} //End if 2
else {
echo "Need: id, title, lon, lat.";
}
} //End if 1
else {
echo "Wrong username or password.";
}
} catch (PDOException $e) {
echo 'Error in sql: ' . $e->getMessage();
}
//Close connection.
$dbh = null;
} //End if 0
else {
echo "Need: id, pass";
}
?>
</body>
</html>