Guest User

Untitled

a guest
Nov 8th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2. if(isset($POST["submit"])){
  3. $hostname='localhost';
  4. $username='root';
  5. $password='';
  6.  
  7. try {
  8. $dbh = new PDO("mysql:host=$hostname;dbname=messages",$username,$password);
  9.  
  10. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  11. $sql = "INSERT INTO contact(user_name, user_email, user_message)
  12. VALUES ('".$POST["user_name"]."','".$_POST["user_email"]."','".$_POST["user_message"]."')";
  13. if ($dbh->querty($sql)) {
  14. echo "<script type= 'text/javascript'>alert('New Record Inserted Succesfully');</script>";
  15. }
  16. else{
  17. echo "<script type= 'text/javascript'>alert('Data not succesfully Inserted.');</script>";
  18. }
  19. $dbh = null;
  20. }
  21. catch(PDOException $e)
  22. {
  23. echo $e->GetMessage();
  24. }
  25.  
  26. }
  27. ?>
Add Comment
Please, Sign In to add comment