Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <form action="add_users.php" method="post">
  5. Login: <input type="text" name="login"><br>
  6. Password: <input type="text" name="password"><br>
  7. Imie: <input type="text" name="name"><br>
  8. Nazwisko: <input type="text" name="surname"><br>
  9. <input type="submit">
  10. </form>
  11. <?php
  12. /*
  13. $login = $_POST["login"];
  14. $password = $_POST["password"];
  15. $name = $_POST["name"];
  16. $surname = $_POST["surname"];
  17. */
  18. $mysql_host = 'localhost';
  19. $port = '3306';
  20. $username = 'root';
  21. $password = '';
  22. $database = 'library';
  23.  
  24. try {
  25. $pdo = new PDO('mysql:host='.$mysql_host.';dbname='.$database.';port='.$port, $username, $password );
  26. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  27.  
  28. $liczba = $pdo->exec('INSERT INTO `users_list` (`login`, `password`, `name`, `surname`) VALUES(
  29. \''.$_POST['login'].'\',
  30. \''.$_POST['password'].'\',
  31. \''.$_POST['name'].'\',
  32. \''.$_POST['surname'].'\')');
  33.  
  34. if($liczba > 0)
  35. {
  36. echo 'Dodano: '.$liczba.' rekordow';
  37. }
  38. else
  39. {
  40. echo 'Wystąpił błąd podczas dodawania rekordów!';
  41. }
  42.  
  43. } catch (PDOException $e) {
  44. print "Error!: " . $e->getMessage() . "<br/>";
  45. die();
  46. }
  47.  
  48.  
  49.  
  50. ?>
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement