Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require './Contact.php'; // sprawdzimy pitem czy dobrze to
- $host = 'localhost';
- $user = 'root';
- $password = '';
- $db = 'ContactList';
- $mysqli = new mysqli($host,$user,$password,$db);
- //$edit = ($_GET['edit']);
- /* dokoncz tu :) */
- if(isset($_GET['edit'])){
- $edit = ($_GET['edit']);
- echo $edit;
- edicik($mysqli,$edit);
- }
- elseif(isset($_GET['delete'])){
- $delete = ($_GET['delete']);
- delejcik($mysqli,$delete);
- }else{
- insercik($mysqli);
- }
- if ($mysqli->connect_errno) {
- echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- }
- $stmt = $mysqli->prepare("SELECT id, firstname, lastname, phone, email FROM contact");
- $stmt->execute();
- $res = $stmt->get_result();
- $stmt->close();
- ?>
- <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
- <table>
- <tr>
- <th>id</th>
- <th>fistname</th>
- <th>lastname</th>
- <th>number</th>
- <th>email</th>
- <th>edit</th>
- <th>remove</th>
- </tr>
- <?php while($row = $res->fetch_assoc()): ?>
- <tr>
- <td><?= $row['id'] ?></td>
- <td><?= $row['firstname'] ?></td>
- <td><?= $row['lastname'] ?></td>
- <td><?= $row['phone'] ?></td>
- <td><?= $row['email'] ?></td>
- <td><a href=index.php?edit=<?= $row['id'] ?> ><i style="color:red" class="fa fa-edit"></i></a></td>
- <td><a href=index.php?delete=<?= $row['id'] ?> ><i style="color:blue" class="fa fa-close"></i></a></td>
- </tr>
- <?php endwhile; ?>
- </table>
- <?php if(isset($_GET['edit'])): ?>
- <form action="index.php" method="POST">
- <span>You edit record with ID <?php $_GET['edit'] ?> </span>
- <span>Imie:</span> <input type="text" name="imieE"></input><br>
- <span>Nazwisko:</span> <input type="text" name="nazwE"></input><br>
- <span>Telefon:</span> <input type="text" name="telE"></input><br>
- <span>Email:</span> <input type="text" name="mailE"></input><br>
- <input type="submit" value="zmien mordeczke"></input>
- </form>
- <?php else: ?>
- <form action="index.php" method="POST">
- <span>Imie:</span> <input type="text" name="imie"></input><br>
- <span>Nazwisko:</span> <input type="text" name="nazw"></input><br>
- <span>Telefon:</span> <input type="text" name="tel"></input><br>
- <span>Email:</span> <input type="text" name="mail"></input><br>
- <input type="submit" value="dosmaz mordeczke"></input>
- </form>
- <?php endif; ?>
- <?php
- function insercik($baza){
- $nejm = '';
- $sernejm = '';
- $fon = '';
- $mejl = '';
- if(isset($_POST['imie'])){
- $nejm = $_POST['imie'];
- }
- if(isset($_POST['nazw'])){
- $sernejm = $_POST['nazw'];
- }
- if(isset($_POST['tel'])){
- $fon = $_POST['tel'];
- }
- if(isset($_POST['mail'])){
- $mejl = $_POST['mail'];
- }
- $stmt = $baza->prepare("INSERT INTO contact(firstname, lastname, phone, email) VALUES ('$nejm', '$sernejm', '$fon', '$mejl');");
- $stmt->execute();
- $stmt->close();
- }
- function edicik($baza,$ed){
- $nejm = '';
- $sernejm = '';
- $fon = '';
- $mejl = '';
- echo "edit";
- echo $ed;
- if(isset($_POST['imieE'])){
- $nejm = $_POST['imieE'];
- }
- if(isset($_POST['nazwE'])){
- $sernejm = $_POST['nazwE'];
- }
- if(isset($_POST['telE'])){
- $fon = $_POST['telE'];
- }
- if(isset($_POST['mailE'])){
- $mejl = $_POST['mailE'];
- }
- echo $nejm;
- echo $sernejm;
- echo $fon;
- echo $mejl;
- $stmt = $baza->prepare("UPDATE contact SET firstname='$nejm', lastname='$sernejm', phone='$fon', email='$mejl' WHERE id='$ed';");
- $stmt->execute();
- $stmt->close();
- }
- function delejcik($baza,$del){
- $stmt = $baza->prepare("DELETE FROM contact WHERE id='$del';");
- $stmt->execute();
- $stmt->close();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement