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


Getting Warning about json_encode 2nd param

Warning: json_encode() expects parameter 2 to be integer, string given in C:\wamp64\www\teamtreehouse\techdegrees\php\php-tech-degree-unit05\mvc-framework\src\routes.php on line 22

// Route to POST
    $app->post('/contact', function (Request $request, Response $response, array $args) use ($container) {
        // Get the args from the POSTed form
        $args = array_merge($args, $request->getParsedBody());
//        var_dump($args);
        if( !empty($args['name']) && !empty($args['email']) && !empty($args['msg']) ) {
            $mail = json_encode($args['name'], $args['email'], $args['msg']);
            return $container->get('view')->render($response, 'thankyou.phtml', $args);
        // Render index view
        return $container->get('view')->render($response, 'contact-form.phtml', $args);

1 Answer

Just realized the problem.. should be feeding as an array to json... like...

$mail = json_encode([$args['name'], $args['email'], $args['msg']]);