edit

edit.php – modify a todo

//Surprise, surprise, using Prosper
namespace Prosper;

//Configure Prosper
require_once 'config.php';

if($_SERVER['REQUEST_METHOD'] == 'POST') {
  //Edit the todo
  Query::update('todo')          //Perform an update
    ->set('title', $_POST)       //Pull title from $_POST
    ->where("id = :id", $_POST)  //Named params
    ->execute();                 //Execute query

  //Redirect to index.php
  header("Location: index.php");
} else {
  //Pretty header
  include_once 'header.php';

  $todos = Query::select()      //Get the todo we are editing
    ->from('todo')              //From the todo table
    ->where("id = :id", $_GET)  //By its id
    ->execute();                //Do it to it

  //There should only be one result
  $todo = $todos[0];

  //Simple for action="edit.php" method="post"
  edit_form($todo)

  //Pretty footer
  include_once 'footer.php';
}

Nothing too spectacular going on here, a fairly straightforward way to perform an edit. The interesting piece to care about here is the named parameters in the where function. The final parameter is checked for a matching key and its value is interpolated in place of the named parameter. This interpolation is done by Prosper, so your choice of backend and its support for named parameters is unimportant.

configindexcreate – edit – delete