Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4.  
  5. <!DOCTYPE html>
  6.  
  7. <head>
  8. <title>Samochody</title>
  9. </head>
  10.  
  11. <body>
  12. <form method="post" action="index.php">
  13. Nazwa: <input type="text" size="12" maxlength="12" name="nazwa"><br />
  14. Waga: <input type="text" size="12" maxlength="36" name="model"><br />
  15. Kolor: <input type="text" size="12" maxlength="36" name="pojemnosc"><br />
  16. Dlugosc: <input type="text" size="12" maxlength="36" name="przebieg"><br />
  17. Szerokosc: <input type="text" size="12" maxlength="36" name="iloscPaliwa"><br />
  18. <input type="submit" value="Wyslij" name="wyslij">
  19. </form>
  20. </body>
  21.  
  22. </html>
  23.  
  24. <?php
  25. class material
  26. {
  27. public $nazwa;
  28. public $waga;
  29. public $kolor;
  30. public $dlugosc;
  31. public $szerokosc;
  32.  
  33. function __construct()
  34. {
  35. $this->nazwa = "Brak danych";
  36. $this->waga = "Brak danych";
  37. $this->kolor = "Brak danych";
  38. $this->dlugosc = "Brak danych";
  39. $this->szerokosc = "Brak danych";
  40. }
  41.  
  42. function wyswietl()
  43. {
  44. echo "<table border>";
  45. echo "<tr><td>Nazwa</td>" . "<td>" . $this->nazwa . "</td></tr>";
  46. echo "<tr><td>Waga</td>" . "<td>" . $this->waga . "</td></tr>";
  47. echo "<tr><td>Kolor: " . "<td>" . $this->kolor . "</td></tr>";
  48. echo "<tr><td>Dlugosc: " . "<td>" . $this->dlugosc . "</td></tr>";
  49. echo "<tr><td>Szerokosc: " . "<td>" . $this->szerokosc . "</td></tr>";
  50. echo "</table>";
  51. }
  52.  
  53. function wprowadz($nazwa, $waga, $kolor, $dlugosc, $szerokosc)
  54. {
  55. $this->marka = $marka;
  56. $this->model = $model;
  57. $this->pojemnosc = $pojemnosc;
  58. $this->przebieg = $przebieg;
  59. $this->iloscPaliwa = $iloscPaliwa;
  60. $this->spalanie = $spalanie;
  61. }
  62.  
  63. function tankuj($kilometry)
  64. {
  65. $this->iloscPaliwa = $this->iloscPaliwa + $kilometry;
  66. }
  67.  
  68. function jedz($kilometry)
  69. {
  70. $this->iloscPaliwa = $this->iloscPaliwa - ($this->spalanie / 100) * $kilometry;
  71. $this->przebieg = $this->przebieg + $kilometry;
  72. }
  73. }
  74.  
  75. // $samochod_1 = new samochody();
  76. // if (isset($_POST["przycisk"])) {
  77. // if (($_POST["przycisk"] === "Wyslij")) {
  78. // $samochod_1->wprowadz($_POST["marka"], $_POST["model"], $_POST["pojemnosc"], $_POST["przebieg"], $_POST["iloscPaliwa"], $_POST["spalanie"]);
  79. // $_SESSION["samochod_1"] = $samochod_1;
  80. // header("Refresh:0");
  81. // }
  82. // }
  83. // $samochod_1 = $_SESSION["samochod_1"];
  84. // $samochod_1->wyswietl();
  85.  
  86. // if (isset($_POST["przycisk"])) {
  87. // if (isset($_POST["kilometry"]) || $_POST["przycisk"] === "Jedz") {
  88. // if ($_POST["przycisk"] === "Jedz") {
  89. // header("Refresh:0");
  90.  
  91. // $samochod_1->jedz($kilometry);
  92. // }
  93. // }
  94. // }
  95. // if (isset($_POST["przycisk"])) {
  96. // if ($_POST["przycisk"] === "Tankuj") {
  97. // $samochod_1->tankuj($kilometry);
  98. // header("Refresh:0");
  99. // }
  100. // }
  101.  
  102. $test = new material();
  103.  
  104.  
  105.  
  106.  
  107.  
  108. // ZAPIS DO PLIKU
  109. // $testData = serialize( $test);
  110. // $sciezka = "dane.txt";
  111. // if (is_writable($sciezka)) {
  112. // $plikDane = fopen($sciezka, "a");
  113. // fwrite($plikDane, $testData);
  114. // fwrite($plikDane, "\n");
  115. // fclose($plikDane);
  116. // }
  117.  
  118. // ODCZYT Z PLIKU
  119. $sciezka = "dane.txt";
  120. if (file_exists($sciezka)){
  121. $plikDane = file($sciezka);
  122. $dane = unserialize($plikDane[0]);
  123. if (!empty($dane)){
  124. $nazwa = $test->nazwa;
  125. $waga = $test->waga;
  126. $kolor = $test->kolor;
  127. $dlugosc = $test->dlugosc;
  128. $szerokosc = $test->szerokosc;
  129. }
  130. }
  131.  
  132.  
  133.  
  134. // WYSWIETLA DANA LINIJKE
  135. // $myFile = "dane.txt";
  136. // $lines = file($myFile);//file in to an array
  137. // echo $lines[0]; //line 2
  138.  
  139. $test->wyswietl();
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement