Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <?php
  2. $user = "root"; #variable to store database username
  3. $pass = "root"; #variable to store database password
  4.  
  5. $dbh = new PDO('mysql:host=127.0.0.1;dbname=SSL;port=8889', $user, $pass); #connects to the datbase and logs in
  6.  
  7. $contactId = $_GET['id'];
  8. echo $contactId;
  9.  
  10. if($_SERVER['REQUEST_METHOD']=='POST') {
  11.     $fName = $_POST['fName'];  
  12.     $lName = $_POST['lName'];
  13.     $phone = $_POST['phone'];
  14.     $email = $_POST['email'];
  15.     $website = $_POST['website'];
  16.     $stmt = $dbh->prepare('UPDATE contacts SET firstName = :firstname, lastName = :lastname, phone = :phone, email = :email, website = :website WHERE id = :id;'); #prepares a sql statment to update a row
  17.     $stmt->bindParam(':firstname', $fName); # binds the information from the $fName varaible to :firstname to be added to the database
  18.     $stmt->bindParam(':lastname', $lName);
  19.     $stmt->bindParam(':phone', $phone);
  20.     $stmt->bindParam(':email', $email);
  21.     $stmt->bindParam(':website', $website);
  22.     $stmt->bindParam(':id', $contactId);
  23.     $stmt->execute();
  24.  
  25.     header('Location: contacts.php'); #returns to main page
  26.     die(); #exits the script
  27. }
  28. ?>
  29. <!DOCTYPE html>
  30. <html>
  31.     <head>
  32.         <title>Update Contacy</title>
  33.         <link rel="stylesheet" type="text/css" href="css/main.css" />
  34.     </head>
  35.     <body>
  36.     <section>
  37.         <h2>Please Update Contact</h2>
  38.         <form action="updatecontact.php" method="POST">
  39.             <label for="fName">First Name:</label><input type="text" name="fName" id="fName" value="" placeholder="First Name" required/>
  40.             <label for="lName">Last Name:</label><input type="text" name="lName" id="lName"  value="" placeholder="Last Name" required/> </br>
  41.             <label for="phone">Phone Number:</label><input type="text" name="phone" id="phone" value="" placeholder="123-123-1234"requied/> </br>
  42.             <label for="email">Email:</label><input type="text" name="email" id="email"  value="" placeholder="test@test.com" required/> </br>
  43.             <label for="website">Website:</label><input type="text" name="website" id="website"  value="http://" required/> </br>
  44.             <input type="submit" name="submit" value="Submit"/> </br>
  45.         </form>
  46.     </section>
  47.     </body>
  48. </hmtl>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement