-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateProject.php
52 lines (38 loc) · 1.58 KB
/
createProject.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
<?php
require_once 'headerFunctions.php';
require_once 'dbConnExec.php';
$projectName = $_POST["projectName"];
$errorMessages = '';
if(! empty($_POST)) {
if(empty($projectName)) {
$errorMessages .= "<li>Project Name is a required field.</li>";
}
if(empty($errorMessages)) {
// make sure that the user name is not already being used
$conn = dbConnect();
$stmt = $conn->prepare('select name from Project where name = :projectName');
$stmt->bindParam(':projectName', $projectName, PDO::PARAM_STR);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC); //retreive the rows as an associative array
if(count($results) > 0) {
$errorMessages .= "<li>That Project Name is already being used. Please choose another.</li>";
} else {
$userId = getCurrentUserId();
$query = $conn->prepare('insert into project (name, id) values (:name, :userId)');
$query->bindParam(':name', trim($projectName));
$query->bindParam(':userId', trim($userId));
$query->execute();
$projectId = $conn->lastInsertId();
}
dbDisconnect($conn);
}
}
if(!empty($errorMessages)) {
require_once 'home.php';
}
else {
require_once 'header.php';
require_once 'projectEditInclude.php';
}
require_once 'footer.php';
?>