RealiteyTv

PHP

Sep 20th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "edel187211"
  6.  
  7.  
  8. try {
  9. $conn = new PDO("mysql:host=$servername;dbname=chat", $username, $password);
  10.  
  11. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. echo "Connection successful"
  13. }
  14.  
  15. catch(PDOException $e)
  16. {
  17. echo "Connection failed: " . $e->getMessage();
  18. }
  19.  
  20.  
  21. if(isset($_POST['text']) && isset($_POST['name']))
  22. {
  23. $text = strip_tags(stripslashes($_POST['text']));
  24. $name = strip_tags(stripslashes($_POST['name']));
  25.  
  26. if(!empty($text) && !empty($name))
  27. {
  28. $insert = $db->prepare("INSERT INTO messages VALUES('','".$name."','".$text."')");
  29. $insert->execute();
  30.  
  31. echo "<li class = 'cm'><b>".ucwords($name)."</b> - ".$text."</li>";
  32. }
  33. }
  34. ?>
Add Comment
Please, Sign In to add comment