daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. <?php //die (print_r ($_POST));
  5.  
  6. $servername = "localhost";
  7. $username = "root";
  8. $password = "";
  9. $dbname = "kontaktai";
  10.  
  11. if (isset($_POST['submit']))
  12. {
  13.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  14.     if (!$conn)
  15.         die("Connection failed");
  16.     echo "Paspaudei mygtuka saugoti!";
  17.     $vardas = trim($_POST["Vardas"]);
  18.     $pavarde = trim($_POST["Pavarde"]);
  19.     if (isset($_POST["Lytis"])){
  20.         $lytis = $_POST["Lytis"];
  21.     }
  22.     else {
  23.         $lytis = '';
  24.     }
  25.     $miestas = $_POST["Miestas"];
  26.     if(isset($_POST["Hobiaim"])){
  27.     $hs = $_POST["Hobiaim"];
  28.     }
  29.     else {
  30.         $hs = '';
  31.     }
  32.     if(isset($_POST["Hobiais"])){
  33.     $hm = $_POST["Hobiais"];}
  34.     else {
  35.         $hm = '';
  36.     }
  37.     if(isset($_POST["Hobiaif"])){
  38.     $hf = $_POST["Hobiaif"];}
  39.     else {
  40.         $hf = '';
  41.     }
  42.  
  43.     $apie = $_POST["Apie"];
  44.    
  45.    
  46.     if (($vardas == '') || ($lytis == '') || ($pavarde == '')){
  47.         echo "Truksta duomenu!";
  48.     }
  49.     else{
  50.         if (strlen($vardas) < 3 || strlen($pavarde) < 3){
  51.             echo "Per trumpas vardas ir/arba pavarde";
  52.         }
  53.         else {
  54.         $sql = "INSERT INTO `zmogus`
  55.         (`vardas`, `pavarde`, `lytis`, `miestas`, `hm`, `hs`, `hf`, `apie`)
  56.         VALUES ('".$vardas."', '".$pavarde."', '".$lytis."', '".$miestas."', '".$hm."', '".$hs."', '".$hf."', '".$apie."');";
  57.         if (mysqli_query($conn, $sql))
  58.        
  59.             {echo "Valio bus olaus";}
  60.         }
  61.     }
  62.    
  63.    
  64.     mysqli_close($conn);
  65. }
  66.  
  67.  
  68.  
  69.  
  70. ?>
  71. <html>
  72. <body style="background-color:#cce6ff">
  73.  
  74. <form action="forma.php" method="post">
  75.  
  76. Vardas:
  77. <input type="text" name="Vardas" value="<?php echo (isset($_POST["Vardas"])? $_POST["Vardas"] : "");?>"><br>
  78. Pavarde:
  79. <input type="text" name="Pavarde" value="<?php echo (isset($_POST["Pavarde"])? $_POST["Pavarde"] : "");?>"><br>
  80. Lytis:<br>
  81. <input type="radio" name="Lytis" value="Vyras"
  82. <?php if (isset($_POST["Lytis"]) && ($_POST["Lytis"]=="Vyras"))  echo "checked";?>
  83. >Vyras<br>
  84. <input type="radio" name="Lytis" value="Moteris"
  85. <?php if (isset($_POST["Lytis"]) && ($_POST["Lytis"]=="Moteris")) echo "checked";?>
  86. >Moteris<br>
  87.  
  88. Miestas:
  89. <select name="Miestas">
  90. <?php
  91. $miestai = array ("vln" => "Vilnius", "kns" => "Kaunas", "klp" => "Klaipėda", "sia" => "Šiauliai", "pnv" => "Panevezys");
  92. foreach ($miestai as $index => $value){
  93.     if (isset($_POST["Miestas"]) && ($_POST["Miestas"] == $index)) {
  94.         $selected = 'selected';
  95.     }
  96.     else {
  97.         $selected = '';
  98.     }
  99.     echo "<option value='" . $index . "' " . $selected . ">" . $value . "</option>";
  100. }
  101.  
  102.  
  103.  
  104. ?>
  105. </select name="pasrinkimas" ><br>
  106. Hobiai:<br>
  107. <input type="checkbox" name="Hobiaim" value="Muzika"
  108. <?php if (isset($_POST["Hobiai"]) && array_key_exists('m', $_POST["Hobiai"])) echo "checked";?>
  109. >Muzika<br>
  110. <input type="checkbox" name="Hobiais" value="Sportas"
  111. <?php if (isset($_POST["Hobiai2"]) && array_key_exists('s', $_POST["Hobiai2"])) echo "checked";?>
  112. >Sportas<br>
  113. <input type="checkbox" name="Hobiaif" value="Filmai"
  114. <?php if (isset($_POST["Hobiai"]) && array_key_exists('f', $_POST["Hobiai"])) echo "checked";?>
  115. >Filmai<br>
  116. Apie save:<br>
  117. <textarea rows="3" cols="40" name="Apie" ><?php echo (isset($_POST["Apie"])? $_POST["Apie"] : "");?></textarea><br>
  118. <input type="submit" value="Priimti" name="submit"><br>
  119. </form>
  120.  
  121. </body>
  122. </html>
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. <html>
  130.  
  131. <?php
  132. $servername = "localhost";
  133. $username = "root";
  134. $password = "";
  135. $dbname = "kontaktai";
  136.  
  137. $conn = mysqli_connect($servername, $username, $password, $dbname);
  138.     if (!$conn)
  139.         die("Connection failed");
  140.     $sql = "SELECT id, vardas, pavarde, lytis,miestas,hm,hs,hf,apie FROM `zmogus`";
  141. $result = mysqli_query($conn, $sql);
  142.  
  143.  
  144.  
  145. mysqli_close($conn);
  146. ?>
  147.  
  148. <body style="background-color:#cce6ff">
  149.  
  150. <a href="forma.php">Sukurti nauja irasa</a>
  151. <br></br>
  152.  
  153. <table border ="1px", style="width:100%">
  154.   <tr>
  155.     <th>Vardas</th>
  156.     <th>Pavarde</th>
  157.     <th>Lytis</th>
  158.     <th>Miestas</th>
  159.     <th>Hm</th>
  160.     <th>Hs</th>
  161.     <th>Hf</th>
  162.     <th>Apie</th>
  163.     </tr>
  164.     <?php
  165.  
  166. if (mysqli_num_rows($result) > 0) {
  167.  
  168.     while($row = mysqli_fetch_assoc($result)) {
  169.         echo   "<tr><td>". $row["vardas"]. "</td>";
  170.         echo"<td>".$row["pavarde"]."</td>";
  171.             if ($row["lytis"]== "V")
  172.             echo "<td> vyras</td> ";
  173.             else if ($row["lytis"]=="M"){
  174.             echo "<td>moteris</td> ";}
  175.             else echo "<td>kita</td> ";
  176.            
  177.                 if ($row["miestas"]== "vln")
  178.             echo "<td> vilnius</td> ";
  179.             else if ($row["miestas"]=="klp"){
  180.             echo "<td>klaipeda</td> ";}
  181.         else if ($row["miestas"]=="kns"){
  182.             echo "<td>Kaunas</td> ";}
  183.         else if ($row["miestas"]=="sia"){
  184.             echo "<td>siauliai</td> ";}
  185.         else if ($row["miestas"]=="pnz"){
  186.             echo "<td>panevezys</td> ";}
  187.         //else echo "<td>kita</td> ";
  188.         echo"<td>" . $row["hm"]."</td>";
  189.         echo"<td> " . $row["hs"]."</td>";
  190.         echo"<td> " . $row["hf"]." </td>";
  191.         echo"<td>" . $row["apie"]."</td></tr>";
  192.     }
  193. } else {
  194.     echo "0 results";
  195. }
  196.     ?>
  197.    
  198.     </table>
  199.  
  200.  
  201.  
  202.  
  203. </body>
  204. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top