Advertisement
Guest User

Widdup

a guest
Nov 26th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "Stu445";
  4. $password = "Stu4998!";
  5. $dbname = "stu445";
  6. $conn = new mysqli($servername,$username,$password,$dbname);
  7. if ($conn->connect_error) {
  8. die("Connection failed: " . $conn->connect_error);
  9.  
  10. }
  11.  
  12. $Name = $_POST["Name"];
  13. $Description = $_POST["Description"];
  14. $Date = date("Y/m/d");
  15.  
  16.  
  17.  
  18. if ($Name != ""){
  19. $sql = "INSERT INTO comments (Date, Name, Comments) VALUES ('$Date', '$Name', '$Description')";
  20. }
  21.  
  22.  
  23.  
  24. if ($_POST['submit']) {
  25. if (empty($_POST['Name'])){
  26. die('"Name" cannot be empty');
  27. }
  28.  
  29. if (empty($_POST['Description'])){
  30. die('"Description" cannot be empty');
  31. }
  32. }
  33.  
  34. if ($conn->query($sql) === TRUE) {
  35.  
  36. echo "New record created successfully";
  37. }
  38. else {
  39. // Failed
  40. echo "Error: " . $sql . "<br>" . $conn->error;
  41. }
  42.  
  43.  
  44. $conn->close();
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement