Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user = "root"; #variable to store database username
- $pass = "root"; #variable to store database password
- $dbh = new PDO('mysql:host=127.0.0.1;dbname=SSL;port=8889', $user, $pass); #connects to the datbase and logs in
- $contactId = $_GET['id'];
- echo $contactId;
- if($_SERVER['REQUEST_METHOD']=='POST') {
- $fName = $_POST['fName'];
- $lName = $_POST['lName'];
- $phone = $_POST['phone'];
- $email = $_POST['email'];
- $website = $_POST['website'];
- $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
- $stmt->bindParam(':firstname', $fName); # binds the information from the $fName varaible to :firstname to be added to the database
- $stmt->bindParam(':lastname', $lName);
- $stmt->bindParam(':phone', $phone);
- $stmt->bindParam(':email', $email);
- $stmt->bindParam(':website', $website);
- $stmt->bindParam(':id', $contactId);
- $stmt->execute();
- header('Location: contacts.php'); #returns to main page
- die(); #exits the script
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Update Contacy</title>
- <link rel="stylesheet" type="text/css" href="css/main.css" />
- </head>
- <body>
- <section>
- <h2>Please Update Contact</h2>
- <form action="updatecontact.php" method="POST">
- <label for="fName">First Name:</label><input type="text" name="fName" id="fName" value="" placeholder="First Name" required/>
- <label for="lName">Last Name:</label><input type="text" name="lName" id="lName" value="" placeholder="Last Name" required/> </br>
- <label for="phone">Phone Number:</label><input type="text" name="phone" id="phone" value="" placeholder="123-123-1234"requied/> </br>
- <label for="email">Email:</label><input type="text" name="email" id="email" value="" placeholder="test@test.com" required/> </br>
- <label for="website">Website:</label><input type="text" name="website" id="website" value="http://" required/> </br>
- <input type="submit" name="submit" value="Submit"/> </br>
- </form>
- </section>
- </body>
- </hmtl>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement