# I need to pass values to my container to make a query

**URL:** <https://discourse.slimframework.com/t/i-need-to-pass-values-to-my-container-to-make-a-query/497>\
**Category:** Questions\
**Created:** [July 13, 2016, 9:42am UTC](https://discourse.slimframework.com/t/i-need-to-pass-values-to-my-container-to-make-a-query/497 "2016-07-13T09:42:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ismael](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@Ismael](https://discourse.slimframework.com/u/Ismael)\
**Post date:** [July 13, 2016, 9:42am UTC](https://discourse.slimframework.com/t/i-need-to-pass-values-to-my-container-to-make-a-query/497/1 "2016-07-13T09:42:31Z")

</div>

Hello,  
I’m new with Slim. I need help with database management. I intend to implement an API on my website. The structure is:

ndapi  
app  
control  
download  
routes  
vendor  
assets  
images  
views  
download  
user

In the root directory “ndapi” there is a index.php containing the following (I just put the relevant code related to the database question):

$config[‘db’][‘host’] = “xxx”;   
$config[‘db’][‘user’] = “xxx”;  
$config[‘db’][‘pass’] = “xxx”;  
$config[‘db’][‘dbname’] = “xxx”;

$app = new \Slim\App([“settings” =\> $config]);  
$container = $app-\>getContainer();  
$container[‘view’] = new \Slim\Views\PhpRenderer(“views/”);

$container[‘db’] = function ($c) {  
$db = $c[‘settings’][‘db’];  
$pdo = new PDO(“mysql:host=” . $db[‘host’] . “;dbname=” . $db[‘dbname’], $db[‘user’], $db[‘pass’]);  
$pdo-\>setAttribute(PDO::ATTR\_ERRMODE, PDO::ERRMODE\_EXCEPTION);  
$pdo-\>setAttribute(PDO::ATTR\_DEFAULT\_FETCH\_MODE, PDO::FETCH\_ASSOC);  
return $pdo;  
};

I have an user area. The user.php file contained in app/routes does this:

$this-\>map([‘GET’, ‘POST’], ‘/myaccount’, function (Request $request, Response $response)  
{  
$posVars = $request-\>getParsedBody();  
$sql = “SELECT email, pwd FROM downloadTest WHERE email = :email AND pwd = :code”;  
$statement = $this-\>db-\>prepare($sql);  
$statement-\>bindParam(’:email’, $posVars[‘email’]);  
$statement-\>bindParam(’:code’, $posVars[‘pwd’]);  
$statement-\>execute();  
$row = $statement-\>fetch();  
if (!$row) {  
$response = $this-\>view-\>render($response, “user/login.html”, []);  
return $response;  
}  
$response = $this-\>view-\>render($response, “user/myaccount.html”, [“data” =\> $row]);  
return $response;  
});

Then, in ndapi/views/user I have a login.php file with an email/pwd form. The submit button reloads the page and collects the values entered by the user in $ \_POST [].

The question is, How do I make a call to the database? I have the email, I have the pwd, have the connection to the database and the query but not how to send the values to the database. In summary, how I connect login.php with user.php?

I hope I explained.

Thank you very much in advance,

Greetings

---

<div class="post-metadata">

**Author:** ![Ismael](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@Ismael](https://discourse.slimframework.com/u/Ismael)\
**Post date:** [July 13, 2016, 9:46am UTC](https://discourse.slimframework.com/t/i-need-to-pass-values-to-my-container-to-make-a-query/497/2 "2016-07-13T09:46:07Z")

</div>

Myself.  
Sorry, the structure is:  
ndapi  
app  
control  
download  
routes  
vendor  
assets  
images  
views  
download  
user

---

<div class="post-metadata">

**Author:** ![Ismael](https://avatars.discourse-cdn.com/v4/letter/i/ac8455/32.png) [@Ismael](https://discourse.slimframework.com/u/Ismael)\
**Post date:** [July 13, 2016, 9:49am UTC](https://discourse.slimframework.com/t/i-need-to-pass-values-to-my-container-to-make-a-query/497/3 "2016-07-13T09:49:22Z")

</div>

Ok,  
I put an image.  
 ![](https://canada1.discourse-cdn.com/flex030/uploads/slimframework/original/1X/b9ae26944989f17d9e4dcd39585d5e542735ea6e.png)
