Advertisement
Guest User

Create

a guest
Mar 1st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.57 KB | None | 0 0
  1. <?php
  2.  
  3.     session_start();
  4.         if((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==false))
  5.         {
  6.             header('Location: zaloguj.php');
  7.         if(isset($_SESSION))
  8.             exit();
  9.         }
  10.  
  11.         if(isset($_POST['nick1']))
  12.         {
  13.             //Udana walidacja? Załóżmy, że tak!
  14.             $wszystko_OK=true;
  15.  
  16.             //Wybierz nick
  17.             $nick1 = $_POST['nick1'];
  18.             $nick2 = $_POST['nick2'];
  19.  
  20.             //Sprawdzenie długości nick'a
  21.             if ((strlen($nick1)<3) || (strlen($nick1)>20))
  22.             {
  23.                 $wszystko_OK = false;
  24.                 $_SESSION['e_nick']= "Nick musi posiadać od 3 do 20 znaków.";
  25.             }
  26.             if ((strlen($nick2)<3) || (strlen($nick2)>20))
  27.             {
  28.                 $wszystko_OK = false;
  29.                 $_SESSION['e_nick']= "Nick musi posiadać od 3 do 20 znaków.";
  30.             }
  31.  
  32.             //sprawdzenie poprawności nickus
  33.             if(ctype_alpha($nick1)==false)
  34.             {
  35.                 $wszystko_OK=false;
  36.                 $_SESSION['e_nick']="Imię postaci może składać się wyłącznie z liter";
  37.             }
  38.             if(ctype_alpha($nick2)==false)
  39.             {
  40.                 $wszystko_OK=false;
  41.                 $_SESSION['e_nick']="Imię / nazwisko może składać się wyłącznie z liter";
  42.             }
  43.  
  44.             //Wybierz rasę
  45.             $rasa = $_POST['rasa'];
  46.  
  47.             if($rasa=NULL)
  48.             {
  49.                 $wszystko_OK = false;
  50.                 $_SESSION['rasa']= "Wybierz rasę.";
  51.             }
  52.  
  53.  
  54.             //Wybierz płeć
  55.             if($gender=NULL)
  56.             {
  57.                 $wszystko_OK = false;
  58.                 $_SESSION['gender']= "Wybierz płeć.";
  59.             }
  60.  
  61.             //Wybierz charakter
  62.             if($charakter=NULL)
  63.             {
  64.                 $wszystko_OK = false;
  65.                 $_SESSION['charakter']= "Wybierz charakter postaci.";
  66.             }
  67.  
  68.             //Zapamiętaj wprowadzone dane
  69.             $_SESSION['fr_nick1'] = $nick1;
  70.             $_SESSION['fr_nick2'] = $nick2;
  71.             $_SESSION['fr_gender'] = $gender;
  72.             $_SESSION['fr_charakter'] = $charakter;
  73.             $_SESSION['fr_rasa'] = $rasa;
  74.  
  75.             require_once'../connect.php';
  76.  
  77.             mysqli_report(MYSQLI_REPORT_STRICT);
  78.  
  79.             try
  80.             {
  81.                     $polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
  82.                     if ($polaczenie->connect_errno!=0)
  83.                     {
  84.                         throw new Exception(mysqli_connect_errno());
  85.                     }
  86.                     else
  87.                     {
  88.  
  89.                         //Czy nick jest juz zajęty
  90.                         $rezultat= $polaczenie->query("select nick from characters where nick='$nick1' '$nick2'");
  91.                         if(!$rezultat) throw new Exception($polaczenie->error);
  92.  
  93.                         $ile_takich_nickow = $rezultat->num_rows;
  94.  
  95.                         if($ile_takich_nickow>0)
  96.                         {
  97.                             $wszystko_OK = false;
  98.                             $_SESSION['e_nick']= "Istnieje już postać o tym imieniu.";
  99.                         }
  100.  
  101.                         //Podsumowanie
  102.                         if($wszystko_OK==true)
  103.                         {
  104.                             //Dodajemy postac, wszystko działa.
  105.                             if($polaczenie->query("INSERT INTO characters VALUES(char_id=NULL, nick='$nick1''$nick2', gender='$gender', rasa='$rasa', charakter='$charakter')")
  106.                             {
  107.                                 $_SESSION['sukces']=true;
  108.                                 header('Location:sukces.php');
  109.                             }
  110.                             else
  111.                             {
  112.                                 throw new Exception($polaczenie->error);
  113.                             }
  114.                         }
  115.  
  116.                         $polaczenie->close();
  117.                     }
  118.             }
  119.             catch (Exception $e)
  120.             {
  121.                 echo '<div class="error">"Błąd serwera! Proszę spróbować ponownie później."</div>';
  122.             }
  123.         }
  124. ?>
  125.  
  126. <!DOCTYPE HTML>
  127. <html lang="pl">
  128. <head>
  129.     <meta charset="utf-8" />
  130.     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  131.     <title>Asmarion - rejestracja</title>
  132.     <script src="https://www.google.com/recaptcha/api.js" async defer></script>
  133.     <link rel="stylesheet" href="create.css" type="text/css"/>
  134.     <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
  135.  
  136. </head>
  137. <body>
  138.  
  139.     <div id="container">
  140.  
  141.         <div id="topbar">
  142.             <div id="topbarl">
  143.  
  144.             </div>
  145.             <div id="topbarr">
  146.                 <img src="logo1.png">
  147.             </div>
  148.             <div style="clear:both"></div>
  149.         </div>
  150.  
  151.         <div id="menu">
  152.             <a href="index.php"><div class="option">Strona główna </div></a>
  153.             <div class="option">Dwa</div>
  154.             <div class="option">Trzy</div>
  155.             <div class="option">Cztery</div>
  156.             <div class="option">Pięć</div>
  157.             <div class="option">Sześć</div>
  158.             <div style="clear:both"></div>
  159.         </div>
  160.  
  161.  
  162.  
  163.         <div id="sidebar">
  164.             <div class="optionL">Jeden</div>
  165.             <div class="optionL">Dwa</div>
  166.             <div class="optionL">Trzy</div>
  167.             <div class="optionL">Cztery</div>
  168.             <div class="optionL">Pięć</div>
  169.             <div class="optionL">Sześć</div>
  170.         </div>
  171.  
  172.         <div id="content">
  173.             <form method="post">
  174.  
  175.                 Imię postaci: </br> <input type="text" name="nick1"/> <input type="text" name="nick2"/> </br>
  176.                 <?php
  177.                     if(isset($_SESSION['e_nick']))
  178.                     {
  179.                         echo '<div class="error">'.$_SESSION['e_nick'].'</div>';
  180.                         unset($_SESSION['e_nick']);
  181.                     }
  182.                 ?>
  183.  
  184.                 Wybierz płeć: </br> <input type="text" name="gender"/> </br>
  185.  
  186.                 <?php
  187.                     if(isset($_SESSION['e_gender']))
  188.                     {
  189.                         echo '<div class="error">'.$_SESSION['e_gender'].'</div>';
  190.                         unset($_SESSION['e_gender']);
  191.                     }
  192.                 ?>
  193.  
  194.                 Wybierz rasę:  </br> <input type="text" name="rasa"/> </br>
  195.  
  196.                 <?php
  197.                     if(isset($_SESSION['e_rasa']))
  198.                     {
  199.                         echo '<div class="error">'.$_SESSION['e_rasa'].'</div>';
  200.                         unset($_SESSION['e_rasa']);
  201.                     }
  202.                 ?>
  203.  
  204.                 Wybierz charakter: </br> <input type="text" name="charakter"/> </br>
  205.  
  206.                 <?php
  207.                     if(isset($_SESSION['e_charakter']))
  208.                     {
  209.                         echo '<div class="error">'.$_SESSION['e_charakter'].'</div>';
  210.                         unset($_SESSION['e_charakter']);
  211.                     }
  212.                 ?>
  213.  
  214.               <input type="submit" value="create"/>
  215.  
  216.             </form>
  217.         </div>
  218.  
  219.         <div id="rejestracja">
  220.             <form action="logout.php" method="post">
  221.                 <input type="submit" value="Powrót">
  222.                 <a href="logout.php"></a>
  223.                 </input>
  224.         </form>
  225.         </div>
  226.         <div style="clear:both"></div>
  227.  
  228.         <div id="footer">
  229.             No to stopka.
  230.         </div>
  231.  
  232.     </div>
  233.  
  234. </body>
  235. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement