Guest User

Untitled

a guest
Nov 8th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 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.  
  15. <br />
  16. <label>Name</label>
  17. <input type="text" name="user_name" class="form-control" /><br />
  18. <label>Email</label>
  19. <input type="text" name="user_email" class="form-control" /><br />
  20. <div class="form-group">
  21. <label>Message</label>
  22. <textarea class="form-control" rows="4" name="user_message"/></textarea>
  23. </div>
  24. <input type="submit" name="submit" value="Submit" class="btn btn-info" /><br />
  25.  
  26. </form>
  27. </div>
  28. <br />
  29. <!--end of form, post to sql start-->
  30. <?php
  31. if(isset($POST["submit"])){
  32. $hostname='localhost';
  33. $username='root';
  34. $password='';
  35.  
  36. try {
  37. $dbh = new PDO("mysql:host=$hostname;dbname=messages",$username,$password);
  38.  
  39. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  40. $sql = "INSERT INTO contact(user_name, user_email, user_message)
  41. VALUES ('".$POST["user_name"]."','".$_POST["user_email"]."','".$_POST["user_message"]."')";
  42. if ($dbh->querty($sql)) {
  43. echo "<script type= 'text/javascript'>alert('New Record Inserted Succesfully');</script>";
  44. }
  45. else{
  46. echo "<script type= 'text/javascript'>alert('Data not succesfully Inserted.');</script>";
  47. }
  48. $dbh = null;
  49. }
  50. catch(PDOException $e)
  51. {
  52. echo $e->GetMessage();
  53. }
  54.  
  55. }
  56. ?>
  57. </body>
  58. </html>
Add Comment
Please, Sign In to add comment