-
Notifications
You must be signed in to change notification settings - Fork 0
/
createUserCF.php
58 lines (54 loc) · 1.32 KB
/
createUserCF.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
51
52
53
54
55
56
57
58
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
// define variables and set to empty values
$username = $password = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$username = test_input($_POST["name"]);
$password = test_input($_POST["password"]);
$conn =new mysqli("localhost","root","mishra2014","CrowdFluttr");
// Check connection
if ($conn->connect_error)
{
$result=array("DBConnection"=>0);
print json_encode($result);
//die("Connection failed: " . $conn->connect_error);
}
else
{
$result=array("DBConnection"=>1);
}
$sql = " INSERT INTO user (username, pass) VALUES ('$username', '$password')";
if($conn->query($sql)==true)
{
$result=array("UserCreation"=>1);
}
else
{
$result=array("UserCreation"=>0);
$result=$result+array("SQLError"=>$conn->error." in ".$sql);
}
print json_encode($result);
$conn->close();
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>CrowdFluttr Peer Evaluation Demo - Create User</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" name="name">
<br><br>
Password: <input type="password" name="password">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>