-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadduser.php
More file actions
67 lines (55 loc) · 1.79 KB
/
adduser.php
File metadata and controls
67 lines (55 loc) · 1.79 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
<?php
session_start();
if($_POST) {
$username = $_POST['rusername'];
$password = $_POST['password'];
$email = $_POST['e-mail'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$bdate = $_POST['bdate'];
$Bdate = date('Y-m-d',strtotime($bdate));
$checkbox = $_POST['checkbox1'];
if(isset($_POST['section_id'])){
$secid = $_POST['section_id'];
$sql2 = "INSERT INTO account VALUES(
'$username', '$password', '$email', '$fname', '$lname',
'$Bdate' , '$secid', '$checkbox')";
}else{
$sql2 = "INSERT INTO account VALUES(
'$username', '$password', '$email', '$fname', '$lname',
'$Bdate' ,NULL, '$checkbox')";
}
$err = "";
include "connectDB.php";
//ตรวจสอบว่าว่า username และ password(รหัสประจำตัวซ้ำกับผู้อื่นหรือไม่)
$sql = "SELECT username FROM account WHERE username = '$username'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_array($result);
if($username == $row[0]) {
$err = "ล็อกอิน: $username ซ้ำซ้อนกับผู้ที่ลงทะเบียนแล้ว กรุณาแก้ไขใหม";
}
}
if($err == "") {
if(!mysqli_query($conn, $sql2)) {
$err = "เกิดข้อผิดพลาดในการบันทึกข้อมูล กรุณาลองใหม่";
}
}
if($err != "") {
echo "<script>alert('$err');</script>";
echo mysqli_error($conn);
mysqli_close($conn);
exit;
}
echo "
<script>
setInterval(function() { location.href = 'editaccount.php'; }, 500);
$('form')[0].reset();
</script>";
mysqli_close($conn);
exit;
}
?>
<script type="text/javascript">
alert('date='+$bdate);
</script>