Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <--in defs.php-->
  2.  
  3. function add_job($title, $description, $salary, $location, $employerId) {
  4. try {
  5. $db = db_open();
  6. $sql = "insert into jobs (title, description, salary, location, employerId) " .
  7. "values (:title, :description, :salary, :location, :employerId)";
  8. $statement = $db->prepare($sql);
  9. $statement->bindValue(':title', $title);
  10. $statement->bindValue(':description', $description);
  11. $statement->bindValue(':salary', $salary);
  12. $statement->bindValue(':location', $location);
  13. $statement->bindValue(':employerId', $employerId);
  14. $statement->execute();
  15. $id = $db->lastInsertId();
  16. } catch(PDOException $e) {
  17. die("Error: " . $e->getMessage());
  18. }
  19. return $id;
  20. }
  21.  
  22.  
  23.  
  24. <--add_job.php-->
  25.  
  26. <?php
  27. /*
  28. * Adds new item from form data.
  29. */
  30. require '../Smarty/libs/Smarty.class.php';
  31. require "includes/defs.php";
  32.  
  33. $employerId = $_GET['id'];
  34.  
  35. # Get form data
  36. $title = $_POST['title'];
  37. $description = $_POST['description'];
  38. $salary = $_POST['salary'];
  39. $location = $_POST['location'];
  40.  
  41.  
  42. # add new item with form data
  43. $id = add_job($title,$description,$salary,$location,$employerId);
  44.  
  45. header("Location: item_detail.php?id=$id");
  46. exit;
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement