insert.php
566 Bytes
<?php
session_start();
//include database connection data
include_once "dbconnection.php";
//make the query
$query = "INSERT INTO toDoList (task, userID) VALUES (?,?) ";
//prepare empty values as placeholders
$query = $link->prepare($query1);
//bind variables to the prepared query
$query -> bind_param('si', $_POST['task'], $_SESSION['id']);
//execute the query
$query -> execute();
//return the last id task as response
$last_id = mysqli_insert_id($link);
echo $last_id;
//close the statement
$query -> close();
//close the connection
$link -> close();
?>