-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
85 lines (82 loc) · 2.26 KB
/
main.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
<?php
include 'admin/error.php';
class user
{
private $conn='';
function __construct()
{
include 'admin/database/db.php';
//$conn= new mysqli('localhost','root','','saustudy');
$this->db=$conn;
}
function insert($fname,$lname,$email,$username,$password)
{
$sql="INSERT INTO `users`(`fname`, `lname`, `email`, `username`, `pass`) VALUES ('$fname','$lname','$email','$username','$password')";
$res=mysqli_query($this->db,$sql);
return $res;
}
function edit($id,$fname,$lname,$email,$username,$password)
{
$sql="UPDATE `users` SET `fname`='$fname',`lname`='$lname',`email`='$email',`username`='$username',`pass`='$password' WHERE `id`='$id'";
$res=mysqli_query($this->db,$sql);
return $res;
}
function delete($id)
{ $sql="DELETE FROM `users` WHERE `id`='$id'";
$res=mysqli_query($this->db,$sql);
return $res;
}
function view()
{
$sql="SELECT * FROM `users`";
$res=mysqli_query($this->db,$sql);
return $res;
}
}
$obj=new user();
if(isset($_POST['submit']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$res=$obj->insert($fname,$lname,$email,$username,$password);
if($res)
{
header("location:view.php");
}
else{
echo"alert('data not inserted successfully')";
}
}
elseif(isset($_POST['update']))
{
$id=$_POST['id'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$res=$obj->edit($id,$fname,$lname,$email,$username,$password);
if($res)
{
header("location: view.php");
}
else{
echo"data not updated successfully";
}
}
elseif(isset($_POST['delete']))
{
$id=$_POST['id'];
$res=$obj->delete($id);
if($res)
{
header("location:view.php");
}
else{
echo"not deleted";
}
}
?>