-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdelete.php
More file actions
66 lines (52 loc) · 1.37 KB
/
delete.php
File metadata and controls
66 lines (52 loc) · 1.37 KB
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
66
<?php
require_once('auth.php');
?>
<html>
<head>
<link rel="shortcut icon" href="./images/dblogo.ico" />
<link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="./css/design.css">
<title>Delete Data</title>
</head>
<body>
<div class="logo"></div>
<div class="design-block">
<center>
<h1>Delete Data</h1>
<form action="delete.php" method="get">
<input type="text" value="" placeholder="ID" name="ids">
<button>Delete</button>
</form>
<?php
include 'config.php';
//declare variable. use 'isset' to determine if variable is set and not null. if null, not execute
if(isset($_GET["ids"]))
{
$ids = (isset($_GET["ids"]) ? $_GET["ids"] : null);
try
{
//connect to database
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//delete data from db
$stmt = $conn->prepare("DELETE FROM STUDENTS WHERE STUD_ID=? ");
//execute the sql query
$stmt->execute(array($ids));
echo "<script>alert('Success! Data Deleted.')</script>";
}
catch (PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
//close conection
$conn = null;
}
?>
<br><br>
<div class="back-but">
<a href="home.php"><button type="button">Back</button></a><br>
</div>
</center>
</div>
</body>
</html>