Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- $servername = "localhost";
- $username = "root";
- $password = "root";
- $database = "lamp2proj1";
- $connection = new mysqli($servername, $username, $password, $database);
- if ($connection->connect_error)
- {
- die("Connection failed: " . $connection->connect_error);
- }
- if(isset($_POST['action']) && !empty($_POST['action'])) {
- $action = $_POST['action'];
- switch($action) {
- case 'delete':
- deletePost($connection, $_POST['data']);
- break;
- case 'new':
- newPost();
- break;
- }
- }
- function newPost()
- {
- $sql = "INSERT INTO task (description, priority) VALUES ('".$_POST['description']."', ".$_POST['priority'].")";
- if ($connection->query($sql) === TRUE) {
- echo "New record created successfully";
- header('Location:index.php');
- } else {
- echo "Error: " . $sql . "<br>" . $connection->error;
- }
- $connection->close();
- }
- function deletePost($connection, $ids) {
- $decodeJSON = json_decode($ids);
- // var_dump($decodeJSON);
- foreach($decodeJSON as $id) {
- $sql = "DELETE FROM task WHERE id = $id";
- if ($connection->query($sql) === TRUE) {
- echo "deleted";
- } else {
- echo "Error: " . $sql . "<br>" . $connection->error;
- }
- }
- $connection->close();
- }
- ?>
Add Comment
Please, Sign In to add comment