Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en-GB">
- <head>
- <title>test2.php</title>
- <link rel="stylesheet" href="uplaod1.css">
- </head>
- <body>
- <div class="heading">
- <h2> T0 do list</h2>
- </div>
- <form method="post" action="">
- <?php
- $db = mysqli_connect("localhost", "root", "root", "todo") or die("QUERY failed". mysqli_error($db));
- if (isset($_POST['task'])) {
- $task = $_POST['task'];
- $query = "INSERT INTO tasks(task) VALUES('$task')";
- if(!$run_query = mysqli_query($db, $query)) {
- printf('QUERY failed -- ' . mysqli_error($db) . '<br />');
- } else {
- printf('QUERY ok<br />');
- }
- }
- ?>
- <input type="text" name="task" class="task" />
- <button type="submit" class="add_btn" name="submit">Add the task</button>
- </form>
- <table>
- <thead>
- <tr>
- <th>N</th>
- <th> </th>
- <th>Tasks</th>
- <th> </th>
- <th>Action</th>
- <th> </th>
- <th>Delete</th>
- <th> </th>
- </tr>
- </thead>
- <tbody>
- <?php
- $run_task = mysqli_query($db, "SELECT * FROM tasks LIMT 20");
- while ($row = mysql_fetch_assoc($run_task))
- {
- $id = $row['id'];
- $task1 = $row['task'];
- ?>
- <tr>
- <td>?php echo $id; ?> </td>
- <td>?php echo $task1; ?> </td>
- <td class = "delete"> <a href="index.php?delete=<?php echo $id;?>"> X</a></td>
- </tr>
- <?php } ?>
- </tbody>
- <?php
- if(isset($_GET['delete']))
- {
- $delete = $_GET['delete'];
- $query = "DELETE FROM tasks WHERE id = '$delete'";
- $run - mysqli_query($db,$query);
- if (!$run)
- {
- echo "this wont work";
- }
- else
- {
- header('location: index.php');
- }
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement