-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateProjectCF.php
More file actions
71 lines (67 loc) · 1.71 KB
/
createProjectCF.php
File metadata and controls
71 lines (67 loc) · 1.71 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
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
// define variables and set to empty values
$projectName ="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$projectName = test_input($_POST["name"]);
$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 projects (projname) VALUES ('$projectName')";
if($conn->query($sql)==true)
{
$result=$result+array("ProjectCreation"=>1);
$sql = "SELECT id from projects ORDER BY id DESC LIMIT 1";
$queryResult=$conn->query($sql);
if($queryResult->num_rows != 1)
{
echo '<br>More/Less than 1 rows';
var_dump($queryResult);
}
else
{
$row=$queryResult->fetch_assoc();
$sql = " CREATE TABLE ".$row['id']."_PE ( id int auto_increment, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, username varchar(30) NOT NULL, PRIMARY key(id) )";
if($conn->query($sql)==true)
{
$result=$result+array("ProjectPECreation"=>1);
}
}
}
else
{
$result=$result+array("ProjectCreation"=>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 Project</h2>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Project Name: <input type="text" name="name">
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>