-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertInformation.php
More file actions
141 lines (113 loc) · 3.33 KB
/
insertInformation.php
File metadata and controls
141 lines (113 loc) · 3.33 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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "newdemo";
// Create connection
$conn=new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn -> connect_error) {
die("Connection failed: ".$conn -> connect_error);
}
// --------------------------- Submit ------------------------
//if user click the "submit" button,
//then execute the code below
if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
$fullname=$_POST['fullname'];
$category = '';
if (isset($_POST['category'])) {
$category=$_POST['category'];
}
$address = $_POST['address'];
$email = $_POST['email'];
$sql="insert into userinfo values ('$username', '$password','$fullname', '$address','$category', '$email')";
$result = $conn->query($sql);
$conn -> close();
}
// ------------------------------ Edit --------------------------
$username="";
$password="";
$fullname="";
$address="";
$category='';
$email="";
if(isset($_GET['edit']))
{
$id=$_GET['edit'];
$sql = "SELECT * FROM userinfo where username='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$username=$row['username'];
$password=$row['password'];
$fullname=$row['fullName'];
$address=$row['address'];
$category=$row['category'];
$email=$row['email'];
}
}
}
// -------------------- If edit is set ---------------------
if(isset($_POST['edit'])){
$category =2; // default value is 2
$username=$_POST['username'];
$password=$_POST['password'];
$fullname=$_POST['fullname'];
if(isset($_POST['category']))
{
$category=$_POST['category'];
}
$email=$_POST['email'];
$address=$_POST['address'];
$sql="update userinfo set password='$password',fullName='$fullname',address='$address', category='$category',email='$email' where username='$username'";
$result = $conn->query($sql);
echo "<script>window.location.assign('table_complete.php');</script>";
}
?>
<!doctype html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>User Registration</title>
<link href="global.css" rel="stylesheet">
<style>
</style>
</head>
<body>
<h1>User Registration</h1>
<form class="subform" method="post" action="insertUser.php">
<p>
<label for="username" class="label">User Name</label>
<input type="text" name="username" id="username" value="<?php echo $username; ?>">
</p>
<p>
<label for="password" class="label">Password</label>
<input type="password" name="password" id="password" value="<?php echo $password; ?>">
</p>
<p>
<label for="fullname" class="label">Full Name</label>
<input type="text" name="fullname" id="fullname" value="<?php echo $fullname; ?>">
</p>
<p>
<label for="address" class="label">Address</label>
<textarea name="address" cols="35" rows="4" id="address"><?php echo $address; ?></textarea>
</p>
<p>
<label for="category" class="label">Category</label>
<label class="label2">Student</label> <input type="checkbox" id="category" name="category" value="1" <?php if($category =='1'){echo "checked";} ?> >
</p>
<p>
<label for="email" class="label">Email</label>
<input name="email" id="email" type="email" value="<?php echo $email; ?>" />
</p>
<p>
<input type="submit" name="submit" value="Insert user">
<input name="edit" type="submit" value="edit" />
</p>
</form>
</body>
</html>