Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Updating and Deleting Records Updating Records

Code seems to work but it won't pass. Any thoughts?

I wasn't sure how to go about this task, I probably over complicated things. However, it seems that I did what was asked but I keep getting: "The SQL statement should set the project_id equal to a placeholder."

Any thoughts?

index.php
<?php
function reassign_task($old, $new) {
    include 'connection.php';

    //add code here
  function test($data){

    echo $data;
  }
  $sql_get = 'SELECT title, date, time FROM tasks WHERE project_id = ?';
  $get_results = $db->prepare($sql_get);
  $get_results->bindValue(1, $old);
  $get_results->execute();

  $get_results = $get_results->fetchAll();

  var_dump($get_results[0]['title']);

  $sql_update = 'UPDATE tasks SET title = ?, date = ?, time = ? WHERE project_id = ?';
  try{
  $insert = $db->prepare($sql_update);
  $insert->bindValue(1, $get_results[0]['title']);
  $insert->bindValue(2, $get_results[0]['date']);
  $insert->bindValue(3, $get_results[0]['time']);
  $insert->bindValue(4, $new);
  $insert->execute();


  }catch(Exception $e){
    echo $e;
    return test('false');
  }

  return test('true');

}

1 Answer

The goal of the function is to reassign a task. So you will need just one SQL statement that sets project_id equal to $new where project_id equals $old in tasks.