-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadduser.php
More file actions
115 lines (77 loc) · 2.66 KB
/
adduser.php
File metadata and controls
115 lines (77 loc) · 2.66 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
<?php
echo <<<TAG
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<script type="text/javascript" src="js/scripts.js"></script>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<![endif]-->
</head>
TAG;
if (isset($_POST['username'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$uname = $_POST['username'];
$password = $_POST['password'];
$servername = "127.0.0.1";
$DBusername = "root";
$password = "";
$dbname = "smarthouse";
$conn = new mysqli($servername, $DBusername, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO user(firstname, lastname, password,username)
VALUES ('" . $fname . "', '" . $lname . "', '" . $password . "','" . $uname . "')";
echo <<<TAG
<body>
<div class="form">
TAG;
if ($conn->query($sql) === TRUE) {
echo "<h1>کاربر اضافه شد</h1>";
} else {
if (strpos($conn->error, 'PRIMARY') !== true)
echo "<h1>خطا: " . "<br>" . "نام کاربری وارد شده تکراری است" . "</h1>";
else
echo "<h1>Error: " . "<br>" . $conn->error . "</h1>";
}
echo "<a href=\"#\" onclick=\"back()\" class=\"btn btn-red\">بازگشت</a>";
echo <<<TAG
</div> <!-- /form -->
</body>
TAG;
} else {
echo <<<TAG
<body>
<div class="form">
<div id="signup">
<h1>اضافه کردن کابر</h1>
<form action="./adduser.php" method="post">
<div class="field-wrap">
<input type="text" name="username" required placeholder="نام کاربری">
</div>
<div class="field-wrap">
<input type="text" name="lname" required placeholder="نام">
</div>
<div class="field-wrap">
<input type="text" name="fname" required placeholder="نام خانوادگی">
</div>
<div class="field-wrap">
<input type="password" name="password" required autocomplete="off" placeholder="کلمه عبور"/>
</div>
<button type="submit" class="button button-block"/>اضافه کن!</button>
</form>
</div>
</div> <!-- /form -->
</body>
TAG;
}
echo <<<TAG
</html>
TAG;