-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
73 lines (72 loc) · 1.92 KB
/
functions.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
<?php
include "connection.php";
function idDropDown()
{
global $connection;
$query="Select * from users";
$result=mysqli_query($connection,$query);
if(!$result)
{
echo "Failed".mysqli_error();
}
while($row=mysqli_fetch_row($result))
{
$id=$row[0];//$row['id']
echo "<option value='$id'>$id</option>";
}
}
function updateData()
{
global $connection;
$username=$_POST['username'];
$password=$_POST['pwd'];
$id=$_POST['id'];
$query="Update users SET username='$username',password='$password' where id=$id";
$result=mysqli_query($connection,$query);
if(!$result)
{
echo "Failed".mysqli_error();
}
}
function readData()
{
global $connection;
$query="Select * from users";
$result=mysqli_query($connection,$query);
if($result)
{
echo "<h2 class='text-center'>Reading Data</h2>";
}
while($row=mysqli_fetch_row($result))
{
echo "<pre>";
echo "<br>";
print_r($row);
echo "</pre>";
}
}
function enterData()
{
global $connection;
$username=mysqli_real_escape_string($connection,$_POST['username']);// It allows escape characters to be entered as it's because otherwise fear of SQL injection
$password=mysqli_real_escape_string($connection,$_POST['pwd']);
$password=crypt($password,'$5$rounds=5000$usesomesillystringforsalt$');//SHA-256 crypt algorithm
$query="INSERT into users(username,password) VALUES('$username',' $password')";
$result=mysqli_query($connection,$query);
if(!$result)
{
echo "Failed".mysqli_error();
}
}
function deleteData()
{
global $connection;
$username=$_POST['username'];
$query="DELETE from users where username='$username'";
$result=mysqli_query($connection,$query);
if(!$result)
{
echo "Failed".mysqli_error();
}
}
?>