Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <--in defs.php-->
- function add_job($title, $description, $salary, $location, $employerId) {
- try {
- $db = db_open();
- $sql = "insert into jobs (title, description, salary, location, employerId) " .
- "values (:title, :description, :salary, :location, :employerId)";
- $statement = $db->prepare($sql);
- $statement->bindValue(':title', $title);
- $statement->bindValue(':description', $description);
- $statement->bindValue(':salary', $salary);
- $statement->bindValue(':location', $location);
- $statement->bindValue(':employerId', $employerId);
- $statement->execute();
- $id = $db->lastInsertId();
- } catch(PDOException $e) {
- die("Error: " . $e->getMessage());
- }
- return $id;
- }
- <--add_job.php-->
- <?php
- /*
- * Adds new item from form data.
- */
- require '../Smarty/libs/Smarty.class.php';
- require "includes/defs.php";
- $employerId = $_GET['id'];
- # Get form data
- $title = $_POST['title'];
- $description = $_POST['description'];
- $salary = $_POST['salary'];
- $location = $_POST['location'];
- # add new item with form data
- $id = add_job($title,$description,$salary,$location,$employerId);
- header("Location: item_detail.php?id=$id");
- exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement