O'Reilly logo

CouchDB and PHP Web Development Beginner's Guide by Tim Juravich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — creating a CouchDB document with PHP and curl

We've been using curl through the command line since the beginning of this book, but this time, we are going to trigger a curl statement using PHP.

  1. Let's start by initializing a curl session, executing it, and then closing it. Open index.php in your text editor, and add the following code into the /signup POST route:
    post('/signup', function($app) {
    $user = new stdClass;
    $user->type = 'user';
    $user->name = $app->form('name');
    $user->email = $app->form('email');
    echo json_encode($user);
    $curl = curl_init();
    // curl options
    curl_exec($curl);
    curl_close($curl);
    
    $app->set('message', 'Thanks for Signing Up ' . $app- >form('name') . '!');
    $app->render('home');
    });
    
  2. Now, let's tell curl

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required