-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
157 lines (143 loc) · 7.55 KB
/
index.php
File metadata and controls
157 lines (143 loc) · 7.55 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php if( isset ( $_GET["id" ] ) ) {
require_once "db_connection.php";
$conn = new mysqli( $servername,$username,$password,$dbname );
$sql = "SELECT * FROM users WHERE id=".$_GET['id'].";";
$result = $conn->query( $sql );
$data = $result->fetch_assoc();
}?>
<?php require_once "head.php";?>
<body class="bg-dark-subtle">
<!-- Navbar -->
<?php include 'nav.php'?>
<div class="container-fluid mt-3">
<div class="row justify-content-center">
<div class="col-8 col-md-8 col-sm-10 p-3 border border-info bg-light rounded rounded-3 shadow shadow-2">
<?php if ( isset ( $data ) ):?>
<h1>Edit User</h1>
<?php else:?>
<h1>Add User</h1>
<?php endif;?>
<?php
session_start();
if ( isset ( $_SESSION[ 'errors' ] ) ) {
$errors = $_SESSION[ 'errors' ];
$name = $_SESSION[ 'name' ];
$age = $_SESSION[ 'age' ];
$email = $_SESSION[ 'email' ];
$status = $_SESSION[ 'status' ];
unset( $_SESSION[ 'errors' ] );
unset( $_SESSION[ 'name' ] );
unset( $_SESSION[ 'age' ] );
unset( $_SESSION[ 'email' ] );
unset( $_SESSION[ 'status' ] );
}elseif ( isset( $_SESSION[ 'messages' ] ) ){
$messages = $_SESSION[ 'messages' ];
unset($_SESSION[ 'messages' ]);
foreach ( $messages as $message ) {
echo "<div class='col-12 bg-light rounded border border-success mb-1 p-2'><h3 style='font-size:15px;'>$message</h3></div>";
}
}
?>
<form action="store.php" method="post">
<?php if( isset( $data ) ): ?>
<div class="mb-3">
<label for="id" class="form-label">Id:</label>
<input type="number" class="form-control" id="id" name="id" aria-describedby="emailHelp" value='<?=$data[ "id" ]?>' readonly>
</div>
<?php endif; ?>
<div class="mb-3">
<label for="text" class="form-label">Name:</label>
<?php if( isset( $name ) ): ?>
<input type="text" class="form-control" id="name" name="name" aria-describedby="emailHelp" value="<?= $name ?>">
<?php elseif( isset( $data )): ?>
<input type="text" class="form-control" id="name" name="name" aria-describedby="emailHelp" value="<?= $data["name"] ?>">
<?php else:?>
<input type="text" class="form-control" id="name" name="name" aria-describedby="emailHelp" >
<?php endif;?>
<?php if ( isset( $errors["name"] ) ) {
echo ("<div class='text-danger'>".$errors["name"]."</div>");
}
?>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address:</label>
<?php if( isset( $name ) ): ?>
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" value="<?= $email ?>">
<?php elseif( isset( $data )): ?>
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp" value="<?= $data["email"] ?>">
<?php else: ?>
<input type="email" class="form-control" id="email" name="email" aria-describedby="emailHelp">
<?php endif;?>
<?php if ( isset( $errors["email"] ) ) {
echo ("<div class='text-danger'>".$errors["email"]."</div>");
}
?>
</div>
<div class="mb-3">
<label for="age" class="form-label">Age:</label>
<?php if( isset( $name ) ): ?>
<input type="number" class="form-control" id="age" name="age" aria-describedby="emailHelp" value="<?=$age ?>">
<?php else: ?>
<input type="number" class="form-control" id="age" name="age" aria-describedby="emailHelp" value="<?=$data["age"] ?>">
<?php endif;?>
<?php if ( isset( $errors["age"] ) ) {
echo ("<div class='text-danger'>".$errors["age"]."</div>");
}
?>
</div>
Status:
<?php if ( isset($status) && $status == "active" ): ?>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault1" value="active" checked>
<label class="form-check-label" for="flexRadioDefault1" >
Active
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault2" value="inactive">
<label class="form-check-label" for="flexRadioDefault2" >
InActive
</label>
</div>
<?php elseif ( isset($status) && $status == "inactive" ): ?>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault1" value="active" >
<label class="form-check-label" for="flexRadioDefault1" >
Active
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault2" value="inactive" checked>
<label class="form-check-label" for="flexRadioDefault2" >
InActive
</label>
</div>
<?php else: ?>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault1" value="active" <?php echo((isset($data) && $data["status"]=="active" ? "checked" : "")) ?>>
<label class="form-check-label" for="flexRadioDefault1" >
Active
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="status" id="flexRadioDefault2" value="inactive" <?php echo((isset($data) && $data["status"]=="inactive" ? "checked" : ""))?>>
<label class="form-check-label" for="flexRadioDefault2" >
InActive
</label>
</div>
<?php endif; ?>
<?php if ( isset( $errors["status"] ) ) {
echo ("<div class='text-danger'>".$errors["status"]."</div>");
}
?>
<?php if( isset($data)): ?>
<button type="submit" class="btn btn-secondary">Edit</button>
<?php else: ?>
<button type="submit" class="btn btn-secondary">Submit</button>
<?php endif; ?>
</form>
</div>
</div>
</div>
</body>
<?php require_once "foot.php"?>