-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddadmin.php
50 lines (39 loc) · 1.16 KB
/
addadmin.php
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
<?php
session_start();
// define variables and set to empty values
include("connection.php");
// $r=$conn->query("select * from admin");
// echo $r->num_rows;
$name = $pass = $uname = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$uname = test_input($_POST["uname"]);
$pass = test_input($_POST["pass"]);
$name= test_input($_POST["name"]);
$sql="select * from admin where uname='".$uname."'";
$r=$conn->query($sql);
echo $r->num_rows;
if($r->num_rows==1){
$_SESSION["iserr"]="Username taken!";
header("location:createadmin");
}
else{
$sql="INSERT INTO `admin` (`aid`, `uname`, `pass`, `name`) VALUES (NULL,'".$uname."', '".$pass."','".$name."');";
echo $sql;
// $conn->query($sql);
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
header("location:admindashboard");
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$conn->close();
?>