Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. <!DOCTYPE HTML>  
  2. <html>
  3. <head>
  4. <style>
  5.     .error
  6.     {
  7.         color: #FF0000;
  8.     }
  9.    
  10.     body
  11.     {
  12.         text-align: center;
  13.     }
  14.    
  15.  
  16.    
  17. </style>
  18. </head>
  19. <body>  
  20.  
  21. <?php
  22. $servername = "localhost";
  23. $username = "root";
  24. $password = "";
  25. $db_name = "firma1";
  26.  
  27. $nameErr = "";
  28. $name = "";
  29.  
  30. $conn = new mysqli($servername, $username, $password, $db_name);
  31. if ($conn->connect_error) {
  32.     die("Connection failed: " . $conn->connect_error);
  33. }
  34.  
  35. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  36.   if (empty($_POST["name"])) {
  37.     $nameErr = "To pole jest wymagane";
  38.   } else {
  39.     $sql = test_input($_POST['name']);
  40.     $result = $conn->query($sql);
  41.  
  42.     if ($result->num_rows > 0) {
  43.         while($row = $result->fetch_all()) {
  44.             $name = $row;
  45.         }
  46.     } else {
  47.         echo "0 results";
  48.     }
  49.     $conn->close();
  50.  
  51.   }
  52.  
  53. }
  54.  
  55. function test_input($data) {
  56.   $data = trim($data);
  57.   $data = stripslashes($data);
  58.   $data = htmlspecialchars($data);
  59.   return $data;
  60. }
  61. ?>
  62.  
  63. <h2>Szybki dostep do bazy</h2>
  64. <p><span class="error">* wymagane pole</span></p>
  65. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
  66.   Polecenie: <input type="text" name="name">
  67.   <span class="error">* <?php echo $nameErr;?></span>
  68.   <br><br>
  69.   <input type="submit" name="submit" value="WyΕ›lij polecenie">  
  70. </form>
  71.  
  72. <?php
  73. echo "<h2> Wynik polecenia: </h2>";
  74. print_r($name);
  75. echo "<br>";
  76. ?>
  77.  
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement