Advertisement
rhuntington

Data entry logic

Sep 2nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.01 KB | None | 0 0
  1. <?php
  2.  
  3.     require 'dbconfig.php';
  4.  
  5.     if(isset($_GET['newcontact']) && isset($_GET['newphone']) && isset($_GET['userid'])) {
  6.         $query = $conn->prepare("INSERT INTO contacts (contact, phone, createdbyuserid) VALUES (:newcontact, :newphone, :userid)");
  7.         $query->bindValue(':newcontact', $_GET['newcontact']);
  8.         $query->bindValue(':newphone', $_GET['newphone']);
  9.         $query->bindValue(':userid', $_GET['userid']);
  10.         $query->execute();
  11.         $query->closeCursor();
  12.  
  13.         if(isset($_GET['neworganization'])) {
  14.             $query = $conn->prepare("UPDATE contacts SET organization = :organization WHERE phone = :phone");
  15.             $query->bindValue(':organization', $_GET['neworganization']);
  16.             $query->bindValue(':phone', $_GET['newphone']);
  17.             $query->execute();
  18.             $query->closeCursor();
  19.         }
  20.         if(isset($_GET['newrelationship'])) {
  21.             $query = $conn->prepare("UPDATE contacts SET relationship = :relationship WHERE phone = :phone");
  22.             $query->bindValue(':relationship', $_GET['newrelationship']);
  23.             $query->bindValue(':phone', $_GET['newphone']);
  24.             $query->execute();
  25.             $query->closeCursor();
  26.         }
  27.         if(isset($_GET['newaddress'])) {
  28.             $query = $conn->prepare("UPDATE contacts SET address = :address WHERE phone = :phone");
  29.             $query->bindValue(':address', $_GET['newaddress']);
  30.             $query->bindValue(':phone', $_GET['newphone']);
  31.             $query->execute();
  32.             $query->closeCursor();
  33.         }
  34.         if(isset($_GET['newgroup'])) {
  35.             $query = $conn->prepare("INSERT INTO groups (createdbyuserid, groupname) VALUES (:userid, :groupname)");
  36.             $query->bindValue(':userid', $_GET['userid']);
  37.             $query->bindValue(':groupname', $_GET['groupname'])
  38.             $query->execute();
  39.             $query->closeCursor();
  40.  
  41.             $query = $conn->prepare("UPDATE contacts SET contacts.groupid = (SELECT groupid FROM groups WHERE groupname = :groupname) and phone = :phone");
  42.             $query->bindValue(':groupname', $_GET['groupname']);
  43.             $query->bindValue(':phone', $_GET['newphone']);
  44.             $query->execute();
  45.             $results = $query->fetchAll(PDO::FETCH_ASSOC);
  46.             $query->closeCursor();
  47.         }
  48.  
  49.     }
  50.  
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement