-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_new_admin_code.php
More file actions
58 lines (53 loc) · 1.62 KB
/
admin_new_admin_code.php
File metadata and controls
58 lines (53 loc) · 1.62 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
<?php
session_start();
$adid = $_POST['adid'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$password = $_POST['password'];
//code for value check
if(!empty($adid) || !empty($name) || !empty($email) || !empty($phone) || !empty($dob) || !empty($gender) || !empty($password))
{
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "museumsys";
// create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbName);
if(mysqli_connect_error()){
die('Connect Error(' . mysqli_connect_errno().')'.mysqli_connect_error());
}
else
{
$SELECT = "SELECT ad_id From admin Where ad_id = ? Limit 1";
$INSERT = "INSERT INTO admin(ad_id, ad_name, email, phone, DOB, gender, pass_word) VALUES (?,?,?,?,?,?,?)";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $adid);
$stmt->execute();
$stmt->bind_result($adid);
$stmt->store_result();
$rnum = $stmt->num_rows;
if($rnum==0){
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sssssss", $adid, $name, $email, $phone, $dob, $gender, $password);
$stmt->execute();
$_SESSION['msg'] = "<script>window.alert('New admin created successfully.')</script>";
header("location: admin_menu.php");
}else{
$_SESSION['msg'] = "<script>window.alert('Admin with same ID already exists.')</script>";
header("location: admin_menu.php");
}
$stmt->close();
$conn->close();
}
}
else{
$_SESSION['msg'] = "<script>window.alert('All fields are required')</script>";
die();
header("location: admin_menu.php");
}
?>