Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2. //wlacz wyswietlanie wszystkich bledow
  3. error_reporting(E_ALL);
  4.  
  5.  
  6.  
  7. if ( ! empty( $_POST ) ) {
  8.  
  9. //polaczenie z baza
  10. $mysqli = new mysqli('localhost', 'root', '', 'tibia' );
  11.  
  12. //sprawdzamy polaczenie z baza
  13. if ( $mysqli->connect_error ) {
  14. die('Connect Error: ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error ) ;
  15. }
  16. //dodawania tresci do bazy danych
  17.  
  18. $title = $mysqli->real_escape_string($_POST['title']);
  19. $comment = $mysqli->real_escape_string($_POST['comment']);
  20.  
  21. //ja rozumiem ze polski jezyk fajny ale po anglikansku duzo lepiej
  22. $sql = 'INSERT INTO newsy
  23. ( tytul, tresc )
  24. VALUES ( "'.$title.'", "'.$comment.'" )';
  25.  
  26.  
  27. $insert = $mysqli->query($sql);
  28.  
  29. // sprawdzanie odpowiedzi mysqli
  30. if ( $insert ) {
  31. $success = true;
  32. }else{
  33. $success = false;
  34. $message = "Error: {$mysqli->errno} : {$mysqli->error}";
  35. }
  36.  
  37. // zamkniecie polaczenie z baza danych
  38. $mysqli->close();
  39.  
  40. if($success):
  41. header('Location: index.php?success');
  42.  
  43. //pozniej w index.php mozesz zrobic if(isset($_GET['success']) i wyswietlic jakis message)
  44.  
  45. else: ?>
  46.  
  47. <p class="error"><?php echo $message; ?><p>
  48.  
  49. <?php endif;
  50.  
  51. }
  52. ?>
  53.  
  54.  
  55. <!-- Jesli bez action to wysylasz do tego samego pliku wiec w tym wypadku moze byc bez -->
  56. <form method="POST">
  57. <p><label>Tytul:<input type="text" name="title"></label></p>
  58. <p><label>Tresc:<input type="text" name="comment"></label></p>
  59. <input type="submit" value="Dodaj komentarz">
  60. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement