Creating a unique page for every user using PHP and MYSQL

Solution:

You'll need to add a relationship between todo and user, the best option is a FOREIGN KEY but is optional.

| users    | | todo    |
|

So, you keep your user id when they login inside a $_SESSION and every time you list or insert things on the todo you use this reference:

{-code-2}

On PHP with {-code-3}:

{-code-4}

On PHP with {-code-5} bind parameters you can do in this way:

$stmt = ${-code-5}->prepare("INSERT INTO todos (user_id, title) VALUES (?, ?)");
$stmt->bind_param("is", $user_id, $title);
$res = $stmt->execute();

Answer

| |---------| | id | | id | | username | | user_id | | password | | title | | checked ||||INSERT INTO todo (user_id, title) VALUES (10, 'My Todo') -- or any other id SELECT * FROM todo WHERE user_id = 10 -- or any other id|||PDO|||$stmt = $conn->prepare("INSERT INTO todos (user_id, title) VALUES (:user_id, :title)"); $stmt->execute([':user_id' => $user_id, ':title' => $title]);|||mysqli|||$stmt = $mysqli->prepare("INSERT INTO todos (user_id, title) VALUES (?, ?)"); $stmt->bind_param("is", $user_id, $title); $res = $stmt->execute();

Source