daily pastebin goal
90%
SHARE
TWEET

Untitled

a guest Jan 25th, 2016 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "12345";
  5. $dbname = "mydb";
  6.  
  7. try {
  8.     $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  9.     // set the PDO error mode to exception
  10.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.     $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  12.     VALUES ($_POST["firstname"], $_POST["lastname"],$_POST["email"])";
  13.     // use exec() because no results are returned
  14.     $conn->exec($sql);
  15.     echo "New record created successfully".$_POST["firstname"];
  16.     }
  17. catch(PDOException $e)
  18.     {
  19.     echo $sql . "<br>" . $e->getMessage();
  20.     }
  21.  
  22. $conn = null;
  23. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top