Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <style>
- .error
- {
- color: #FF0000;
- }
- body
- {
- text-align: center;
- }
- </style>
- </head>
- <body>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $db_name = "firma1";
- $nameErr = "";
- $name = "";
- $conn = new mysqli($servername, $username, $password, $db_name);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["name"])) {
- $nameErr = "To pole jest wymagane";
- } else {
- $sql = test_input($_POST['name']);
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_all()) {
- $name = $row;
- }
- } else {
- echo "0 results";
- }
- $conn->close();
- }
- }
- function test_input($data) {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
- ?>
- <h2>Szybki dostep do bazy</h2>
- <p><span class="error">* wymagane pole</span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- Polecenie: <input type="text" name="name">
- <span class="error">* <?php echo $nameErr;?></span>
- <br><br>
- <input type="submit" name="submit" value="WyΕlij polecenie">
- </form>
- <?php
- echo "<h2> Wynik polecenia: </h2>";
- print_r($name);
- echo "<br>";
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement