-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
67 lines (57 loc) · 2.03 KB
/
functions.php
File metadata and controls
67 lines (57 loc) · 2.03 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
67
<?php include "db.php"; ?>
<?php
function pullAllIds(){
global $connection;
$query = "SELECT * FROM users";
$result = mysqli_query($connection,$query);
if(!$result){
die('QUERY FAILED'.mysqli_error($connection));
}
while($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
echo "<option value='$id'>$id</option>";
}
}
function updateData(){
if(isset($_POST['submit'])){
global $connection;
$username = $_POST['username'];
$password = $_POST['password'];
$id = $_POST['id'];
$query = "UPDATE users SET username = '$username', password = '$password' WHERE id = $id";
$result = mysqli_query($connection,$query);
if(!$result){
die('QUERY FAILED.'.mysqli_error($connection));
}
}
}
function createData(){
global $connection;
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$username = mysqli_real_escape_string($connection,$username);
$password = mysqli_real_escape_string($connection,$password);
$hashFormat = "$2y$10$";
$salt = "iusesomecrazystrings22";
$hashFormat_and_salt = $hashFormat.$salt;
$password = crypt($password,$hashFormat_and_salt);
$query = "INSERT INTO users(username,password) VALUES ('$username','$password')";
$result = mysqli_query($connection,$query);
if(!$result){
die('QUERY FAILED'.mysqli_error($connection));
}
}
}
function deleteData(){
if(isset($_POST['submit'])){
global $connection;
$id = $_POST['id'];
$query = "DELETE FROM users where id = $id";
$result = mysqli_query($connection,$query);
if(!$result){
die('QUERY FAILED.'.mysqli_error($connection));
}
}
}
?>