-
Notifications
You must be signed in to change notification settings - Fork 21
/
addpost.php
67 lines (49 loc) · 2.63 KB
/
addpost.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
59
60
61
62
63
64
65
66
67
<?php
//To Handle Session Variables on This Page
session_start();
if(empty($_SESSION['id_company'])) {
header("Location: dashboard_company.php");
exit();
}
//Including Database Connection From db.php file to avoid rewriting in all files
require_once("db.php");
//if user Actually clicked Add Post Button
if(isset($_POST)) {
// New way using prepared statements. This is safe from SQL INJECTION. Should consider to update to this method when many people are using this method.
$stmt = $conn->prepare("INSERT INTO job_post(id_company, jobtitle, description, minimumsalary, maximumsalary, experience, qualification) VALUES (?,?, ?, ?, ?, ?, ?)");
$stmt->bind_param("issssss", $_SESSION['id_company'], $jobtitle, $description, $minimumsalary, $maximumsalary, $experience, $qualification);
$jobtitle = mysqli_real_escape_string($conn, $_POST['jobtitle']);
$description = mysqli_real_escape_string($conn, $_POST['description']);
$minimumsalary = mysqli_real_escape_string($conn, $_POST['minimumsalary']);
$maximumsalary = mysqli_real_escape_string($conn, $_POST['maximumsalary']);
$experience = mysqli_real_escape_string($conn, $_POST['experience']);
$qualification = mysqli_real_escape_string($conn, $_POST['qualification']);
if($stmt->execute()) {
//If data Inserted successfully then redirect to dashboard
$_SESSION['jobPostSuccess'] = true;
header("Location: dashboard_company.php");
exit();
} else {
//If data failed to insert then show that error. Note: This condition should not come unless we as a developer make mistake or someone tries to hack their way in and mess up :D
echo "Error ";
}
$stmt->close();
//THIS IS NOT SAFE FROM SQL INJECTION BUT OK TO USE WITH SMALL TO MEDIUM SIZE AUDIENCE
//Insert Job Post Query
// $sql = "INSERT INTO job_post(id_company, jobtitle, description, minimumsalary, maximumsalary, experience, qualification) VALUES ('$_SESSION[id_company]','$jobtitle', '$description', '$minimumsalary', '$maximumsalary', '$experience', '$qualification')";
// if($conn->query($sql)===TRUE) {
// //If data Inserted successfully then redirect to dashboard
// $_SESSION['jobPostSuccess'] = true;
// header("Location: dashboard.php");
// exit();
// } else {
// //If data failed to insert then show that error. Note: This condition should not come unless we as a developer make mistake or someone tries to hack their way in and mess up :D
// echo "Error " . $sql . "<br>" . $conn->error;
// }
//Close database connection. Not compulsory but good practice.
$conn->close();
} else {
//redirect them back to dashboard page if they didn't click Add Post button
header("Location: create-job-post.php");
exit();
}