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

glen rose
glen rose
1,182 Points

Hi I simply cant figure out, what im doing wrong here. Could somebody please help me? Thanks a lot

task is: Before deleting a project, we want to reassign all tasks associated with that project to another project. The function has been started for you and includes a connection to the database which sets up a PHP Data Object named $db. Use a prepared statement to bind the two parameters to the update SQL statement.

error is: Bummer! Uncaught Error: Call to undefined function bindValue() in index.php:9

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

    //add code here
  $sql ='UPDATE tasks SET project_id=? WHERE project_id=?';

  $results = $db->prepare($sql);
  $results = bindValue(1, $new, PDO::PARAM_INT);
  $results = bindValue(2, $old, PDO::PARAM_INT);
  $results->execute();  

}

1 Answer

Hazem mosaad
Hazem mosaad
15,384 Points

Hi Glen i See Your Code You Have A small mistake Please See The comment

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

    //add code here
  $sql ='UPDATE tasks SET project_id=? WHERE project_id=?';

  $results = $db->prepare($sql);
  $results -> bindValue(1, $new, PDO::PARAM_INT); // Here You Put $results with new value results is object so you must use -> not = i hope this help :)
  $results -> bindValue(2, $old, PDO::PARAM_INT);
  $results->execute();  

}
glen rose
glen rose
1,182 Points

Offcause. thats it, Iยดve looked on this code for such a long time, i got blind :-) Thanks!!! very appriciated