-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.php
101 lines (86 loc) · 3.14 KB
/
logic.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
//include 'functions.php';
/*
$fullname = $_POST['family_n'];
$username = $_POST['name'];
$useremail = $_POST['email'];
$passwrd = sha1($_POST["password"]);
*/
$auth_actions = ['add','delete','update','read'];
if(!empty($_POST['submit'])){
extract($_POST);
if ($action === "add"){
$sql = "INSERT INTO user (Fname, name, email, password, isAdmin, file_path) values(?,?,?,?,?,?)";
$qry = $db->prepare($sql);
$isExecuted = $qry->execute([$family_n,$name,$email,sha1($password),false,null]);
if($isExecuted){
echo "<h1 style='color:green;text-align:center'>user has been inserted</h1>";
}else{
echo "<h1 style='color:red;text-align:center'>Error in db</h1>";
}
}elseif($action === "update"){
$sql = "UPDATE user set Fname = ?, name = ?, email = ?, password = ? where email = ?";
$qry = $db->prepare($sql);
$isExecuted = $qry->execute([$family_n,$name,$email,sha1($password),$email]);
if($isExecuted){
echo "<h1 style='color:green;text-align:center'>user with : $email has been updated</h1>";
}else{
echo "<h1 style='color:red;text-align:center'>Update error</h1>";
}
}elseif($action === "read"){
$sql = "SELECT * FROM user";
$qry = $db->prepare($sql);
$isExecuted = $qry->execute();
$rows = $qry->fetchAll(PDO::FETCH_OBJ);
echo '<ol>';
foreach($rows as $row){
echo '<li>';
echo $row->email . "<br>";
echo '</li>';
}
echo '</ol>';
}elseif($action === "delete"){
$sql = "DELETE FROM user WHERE email = ?";
$qry = $db->prepare($sql);
$isExecuted = $qry->execute([$email]);
if($isExecuted){
echo "<h1 style='color:green;text-align:center'>user with : $email has been deleted</h1>";
}else{
echo "<h1 style='color:red;text-align:center'>Delete error</h1>";
}
}
}
/*
if(isset($_GET)){
extract($_GET);
$account = selectAccount($db,$email);
echo "name : " . $account->name;
}
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title> Crud </title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel='stylesheet' type='text/css' media='screen' href='main.css'>
<script src='main.js'></script>
</head>
<body>
<form method="post">
<input name="family_n" id="f" type="text" placeholder="Fname"> <br>
<input name="name" id="n" type="text" placeholder="name"> <br>
<input name="email" id="em" type="email" placeholder="e-mail"> <br>
<input name="password" id="ps" type="password" placeholder="password"> <br>
<select name="action" id="">
<option value="add" selected>add</option>
<option value="update">update</option>
<option value="delete">delete</option>
<option value="read">read</option>
</select>
<input type="submit" name="submit" value="validate">
</form>
</body>
</html>