Posted By

Vejfil on 05/14/18


Tagged

dotaznik


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Vejfil


dotaznik


 / Published in: PHP
 

dotaznik

  1. <!DOCTYPE html>
  2. <?php
  3. $cookie_value = "uzivatel neni prihlasen";
  4. setcookie("prihlaseni", $cookie_value, time() + (86400 * 30), "/");
  5. ?>
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <title>TEST</title>
  10. <style>
  11. body {background-color: white;}
  12. h1 {color: red;}
  13. #test { position: absolute; top: 100px; left: 100px; width: 50px; height: 50px; border: 1px solid black; background-color: white}
  14. #formul { position: absolute; top: 200px; left: 100px;}
  15. #formu2 { position: absolute; top: 500px; left: 100px;}
  16. #echos { position: absolute; top: 350px; left: 100px; color: white;}
  17.  
  18. </style>
  19. </head>
  20. <body>
  21. <h1> Cus </h1>
  22. <!-- <div id= "test" onclick = "testos()"> test </div> -->
  23. <form action="test.php" method="POST">
  24. <input type="submit" id="odhlas" value="Odhlaseni">
  25. </form>
  26. <?php $VisForm = True;
  27. if (isset($_POST["prih"])) {
  28. $VisForm = False; }
  29. if($VisForm) {
  30. ?>
  31. <div id= "formul">
  32. <form action="test.php" method="POST"> <br> <br>
  33. Jmeno: <input type="text" name="prom1"> <br> <br>
  34. Heslo: <input type="password" name="prom2"> <br> <br>
  35. <input type="submit" name= "reg" value="Registrace">
  36. </form>
  37. </div>
  38. <div id= "formu2">
  39. <form action="test.php" method="POST"> <br> <br>
  40. Jmeno: <input type="text" name="jmeno"> <br> <br>
  41. Heslo: <input type="password" name="heslo"> <br> <br>
  42. <input type="submit" name= "prih" value="Prihlaseni">
  43. </form>
  44. </div> <?php }
  45. ?>
  46.  
  47. <?php
  48.  
  49. // $den="st?eda";
  50. // echo $den;
  51. if (isset($_POST["prom1"])){
  52. $prom1 = $_POST["prom1"]; }
  53. if (isset($_POST["prom2"])){
  54. $prom2 = $_POST["prom2"]; }
  55. if (isset($_POST["jmeno"])){
  56. $jmeno = $_POST["jmeno"]; }
  57. if (isset($_POST["heslo"])){
  58. $heslo = $_POST["heslo"]; }
  59. if (isset($_POST["prom1"]) && isset($_POST["prom2"])){
  60. if ($_POST["prom1"] !== null && $_POST["prom2"] !== null){
  61. echo ' <div id= "echos">'.$prom1.' a '.$prom2. '</div>'; }}
  62. $servername = "localhost";
  63. $username = "root";
  64. $password = "123";
  65. $database = "test";
  66. $conn = new mysqli($servername, $username, $password, $database);
  67. if (isset($_POST["prom1"]) && isset($_POST["prom2"])){
  68. if ($_POST["prom1"] !== null && $_POST["prom2"] !== null){
  69. $sql = "INSERT INTO uzivatele(jmeno, heslo) VALUES ('$prom1', '$prom2')";
  70. $result = mysqli_query($conn, $sql);
  71. } };
  72. if (isset($_POST["jmeno"]) && isset($_POST["heslo"])){
  73. if ($_POST["jmeno"] !== null && $_POST["heslo"] !== null){
  74. $sql = "SELECT jmeno, heslo FROM uzivatele WHERE jmeno = '$jmeno' AND heslo = '$heslo'";
  75. $result = mysqli_query($conn, $sql);
  76. if (mysqli_num_rows($result) == 0){
  77. echo "spatne jmeno nebo heslo";
  78. $prihlaseni = 0;
  79. $cookie_value = "uzivatel neni prihlasen";
  80. }
  81. else {
  82. //echo "uzivatel prihlasen";
  83. $cookie_value = "uzivatel prihlasen";
  84. };
  85. } };
  86. echo $cookie_value;
  87.  
  88. ?>
  89. <script>
  90. function testos(){
  91. alert("funkcni")
  92. };
  93. </script>
  94. </body>
  95. </html>

Report this snippet  

You need to login to post a comment.