davidjmorin

PDO Connection

Jan 26th, 2021 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. require '../assets/connect.php';
  6.  
  7.  
  8.  
  9.  
  10. if(isset($_POST['update'])){
  11.  
  12.  
  13.     error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
  14.  
  15.     /////////////Collect form data/////////////
  16. $name         = !empty($_REQUEST['name'])   ? trim($_REQUEST['name']) : null;
  17. $email        = !empty($_REQUEST['email'])  ? trim($_REQUEST['email']) : null;
  18. $value        = !empty($_REQUEST['value'])  ? trim($_REQUEST['value']) : null;
  19. $contact      = !empty($_REQUEST['contact'])    ? trim($_REQUEST['contact']) : null;
  20. $phone        = !empty($_REQUEST['phone'])  ? trim($_REQUEST['phone']) : null;
  21. $status       = !empty($_REQUEST['status']) ? trim($_REQUEST['status']) : null;
  22. $nextAction   = !empty($_REQUEST['nextAction']) ? trim($_REQUEST['nextAction']) : null;
  23. $storeName    = !empty($_REQUEST['store'])  ? trim($_REQUEST['store']) : null;
  24. $region       = !empty($_REQUEST['region']) ? trim($_REQUEST['region  ']) : null;
  25.  
  26.     $data = [
  27.       'name' => $name,
  28.       'email' => $email,
  29.       'value' => $value,
  30.       'contact' => $contact,
  31.       'phone' => $phone,
  32.       'status' => $status,
  33.       'nextAction' => $nextAction,
  34.       'storeName' => $storeName,
  35.       'region' => $region,
  36.  
  37.    ];
  38.  
  39.    $sql = "INSERT INTO company(companyName, coEmail, Deal_Value, Contact_name, Phone, Status, Next_Action_Item, Store_Name, Region)
  40.           VALUES (:name,
  41.                   :email,
  42.                   :value,
  43.                   :contact,
  44.                   :phone,
  45.                   :status,
  46.                   :nextAction,
  47.                   :storeName,
  48.                   :region
  49.  
  50.            )";
  51.    $stmt= $pdo->prepare($sql);
  52.     if($stmt->execute($data)){
  53.  
  54.  
  55. $_SESSION['success'] = "Successfully Submitted Request";
  56. header('Location: index.php');
  57. exit();
  58. }else{
  59.   $_SESSION['success'] = "Did not send, Try again";
  60. print_r($sql->errorInfo()); // if any error is there it will be posted
  61. $msg=" Database problem, please contact site admin ";
  62. }
  63.  
  64. }
  65. ?>
Add Comment
Please, Sign In to add comment