issue with mysql join table
<p>I have a mysql database with three tables:</p>

<ol>
<li>list of users </li>
<li>list of items</li>
<li>list of tasks table to say which users will do which task (join table)</li>
</ol>

<p>Each day the list of tasks will change. So I will manually change this task list in phpmyadmin. What I want is for every task to be assigned to every user. I can see that this is manually possible in phpmyadmin but it would not really be feasible to do this manually for more than a few users. </p>

<p>I am really struggling to see what I have done wrong in my code. I'm really new to php. When I post the correct url with postman (I am doing an api using slim) it says there were no errors but when I check my mysql database the user task table is still empty. </p>

<p>Here is the code in my index.php:</p>

<pre><code>$app-&gt;post('/tasks', function() use ($app) {

        $headers = apache_request_headers();
        $response = array();

        if (isset($headers['Authorization'])){

        $db = new DbHandler();
        $api_key = $headers['Authorization'];

            if ($api_key == '12345'){
                    $task_id = $db-&gt;createUserTask();

            }else{
                    $response["error"] = true;
                    $response["message"] = "Invalid Api key";
                    echoRespnse(400, $response);
                    $app-&gt;stop();
            }

       }else{

            $response["error"] = true;
            $response["message"] = "Invalid Api Key";
            echoRespnse(400, $response);
            $app-&gt;stop();
  }                
    });
</code></pre>

<p>Here is the code for my createUserTask function with is part of DbHandler:</p>

<pre><code>    public function createUserTask() {

    $no_users = $this-&gt;conn-&gt;prepare("SELECT MAX (id) FROM users");
    $no_tasks = $this-&gt;conn-&gt;prepare("SELECT MAX (id) FROM tasks");

    if ($no_users &gt;= 0 &amp;&amp; $no_tasks &gt;=0){
            for($i = 1; $i == $no_users; $i++){
                    for ($u = 1; $u == $no_tasks; $u++){
                            $stmt = $this-&gt;conn-&gt;prepare("INSERT INTO user_tasks(user_id, task_id) values(i, u)");
                            $result = $stmt-&gt;execute();

                            if (false === $result) {
                                    die('execute() failed: ' . htmlspecialchars($stmt-&gt;error));
                            }
                            $stmt-&gt;close();
                    }
            }
    }
}
</code></pre>

<p>Can you see what i've done wrong?</p>