Guest User

Untitled

a guest
Nov 8th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  7. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  8. </head>
  9. <body>
  10. <br />
  11. <div class="container" style="width:500px;">
  12. <form method="post">
  13.  
  14. if(isset($error))
  15. {
  16. echo $error;
  17. }
  18. ?>
  19. <br />
  20. <label>Name</label>
  21. <input type="text" name="user_name" class="form-control" /><br />
  22. <label>Email</label>
  23. <input type="text" name="user_email" class="form-control" /><br />
  24. <div class="form-group">
  25. <label>Message</label>
  26. <textarea class="form-control" rows="4" name="user_message"/></textarea>
  27. </div>
  28. <input type="submit" name="submit" value="Submit" class="btn btn-info" /><br />
  29.  
  30. </form>
  31. </div>
  32. <br />
  33. <!--end of form, post to sql start-->
  34. <?php
  35. if(isset($POST["submit"])){
  36. $hostname='localhost';
  37. $username='root';
  38. $password='';
  39.  
  40. try {
  41. $dbh = new PDO("mysql:host=$hostname;dbname=messages",$username,$password);
  42.  
  43. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  44. $sql = "INSERT INTO contact(user_name, user_email, user_message)
  45. VALUES ('".$POST["user_name"]."','".$_POST["user_email"]."','".$_POST["user_message"]."')";
  46. if ($dbh->querty($sql)) {
  47. echo "<script type= 'text/javascript'>alert('New Record Inserted Succesfully');</script>";
  48. }
  49. else{
  50. echo "<script type= 'text/javascript'>alert('Data not succesfully Inserted.');</script>;
  51. }
  52. $dbh = null;
  53. }
  54. catch(PDOException $e)
  55. {
  56. echo $e->GetMessage();
  57. }
  58.  
  59. }
  60. ?>
  61. </body>
  62. </html>
Add Comment
Please, Sign In to add comment