Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $user = 'root';
- $pass = 'firma2016';
- $db = 'pailab4';
- $conn = mysql_connect($host, $user, $pass);
- if (!$conn)
- die('Error: ' . mysql_error());
- $db = mysql_select_db($db, $conn);
- if (!$db)
- die('Error: ' . mysql_error());
- session_start();
- if($_POST)
- {
- if($_POST["ocena"])
- {
- $ocena = htmlspecialchars(trim($_POST['ocena']));
- }
- if($_POST["przedmiot"])
- {
- $przedmiot = htmlspecialchars(trim($_POST['przedmiot']));
- }
- if($_POST["add"])
- {
- if(!empty($ocena) && !empty($przedmiot))
- {
- mysql_query("INSERT INTO PAI4 SET ocena = '" .$ocena. "', przedmiot='" .$przedmiot. "'");
- }
- header("Przedmiot?: ?");
- }
- if($_POST["modify"])
- {
- $idEditRow = htmlspecialchars(trim($_POST["idEditRow"]));
- if(!empty($ocena) && !empty($przedmiot))
- {
- mysql_query("UPDATE PAI4 SET ocena = '" .$ocena. "', przedmiot='" .$przedmiot. "' WHERE id = '" .$idEditRow. "'");
- }
- header("Przedmiot?: ?");
- }
- if($_POST["delete"])
- {
- $deleteRow = $_POST["delete"];
- foreach($deleteRow as $idDeleteRow)
- {
- mysql_query("DELETE FROM PAI4 WHERE id = '" .$idDeleteRow. "'");
- header('Przedmiot?: ?');
- }
- $result = mysql_result(mysql_query("SELECT COUNT(*) FROM PAI4"));
- if($result == 0)
- {
- mysql_query("ALTER TABLE PAI4 AUTO_INCREMENT = 1");
- }
- }
- }
- ?>
- <?php
- $orderASC = "asc";
- $orderDESC = "desc";
- $cookieName = "sortTableColumn";
- if(!$_GET)
- {
- $query = "SELECT * FROM PAI4";
- $cookieValue = "asc";
- setcookie($cookieName,$cookieValue);
- }
- else
- {
- $orderSort = $_GET["order"];
- $sort = $_GET['sort'];
- $cookieValue = $_COOKIE[$cookieName];
- if($orderSort == $cookieValue)
- {
- $query = "SELECT * FROM PAI4 ORDER BY " .$sort. " " .$orderDESC;
- $cookieValue = $orderDESC;
- setcookie($cookieName,$cookieValue);
- }
- else
- {
- $query = "SELECT * FROM PAI4 ORDER BY " .$sort. " " .$orderASC;
- $cookieValue = $orderASC;
- setcookie($cookieName,$cookieValue);
- }
- }
- $resultQuery = mysql_query($query);
- echo
- '<form action="?" method="post">
- <input type="hidden" name="delete" value="delete">
- <center>
- <table border="1" style="border-collapse: collapse;font-family: Arial; font-size:14px;">
- <tr>
- <th> <a href="?sort=id&order=asc">ID</a> </th>
- <th> <a href="?sort=ocena&order=asc">OCENA</a> </th>
- <th> <a href="?sort=przedmiot&order=asc">PRZEDMIOT</a> </th>
- <th> <input type="submit" name="edit" value="EDYTUJ"> </th>
- <th> <input type="submit" name="delete" value="USUŃ"> </th>
- </tr>';
- while($row=mysql_fetch_row($resultQuery))
- {
- echo '<tr>
- <td>' .$row[0]. '</td>
- <td>' .$row[1]. '</td>
- <td>' .$row[2]. '</td>
- <td> <input type="radio" name="idEditRow" value=' .$row[0]. '></td>
- <td> <input type="checkbox" name="delete[]" value=' .$row[0]. '> </td>
- </tr>';
- }
- echo "</table></form><hr>";
- $result = mysql_result(mysql_query("SELECT MAX(id) as id FROM PAI4"),0) + 1;
- echo
- '<p style="font-family: Arial; font-size: 14px;"><strong>Dodawanie:</strong></p>
- <form action="?" method="post">
- <input style="max-width: 30px;" type="text" name="id" placeholder = "' .$result. '" readonly>
- <input type="text" name="ocena" placeholder="Ocena">
- <input type="text" name="przedmiot" placeholder="Przedmiot">
- <input type="submit" name="add" value="Dodaj">
- </form></center>';
- if($_POST["edit"])
- {
- $idEditRow = $_POST["idEditRow"];
- if($idEditRow >= 1)
- {
- echo
- '<center><hr>
- <p style="font-family: Arial; font-size: 14px;"><strong>Modyfikacja:</strong></p>
- <form action="z2.php" method="post">
- <input style="max-width: 30px;" type="text" name="id" placeholder = "' .$idEditRow. '" readonly>
- <input type="text" name="ocena" placeholder="Ocena">
- <input type="text" name="przedmiot" placeholder="Przedmiot">
- <input type="hidden" name="idEditRow" value="' .$idEditRow. '">
- <input type="submit" name="modify" value="Edytuj"><hr style="margin-top: 16px;"></center>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement