Browse Source

move create sql to DB class/file

master
Lennart Verschelden 2 years ago
parent
commit
cd20300052
3 changed files with 10 additions and 5 deletions
  1. 0
    0
      db.sqlite3
  2. 3
    5
      public/index.php
  3. 7
    0
      src/DB/DB.php

+ 0
- 0
db.sqlite3 View File


+ 3
- 5
public/index.php View File

@@ -13,12 +13,10 @@ require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();

$app->map(['GET', 'POST'], "/orders/{client}/create", function (Request $request, Response $response, array $args) {
$db2 = new DB();
$client = $args['client'];
$a = $db2->getClientInfo($client);
if ($request->getMethod() == "GET") {
$db2 = new DB();
$stmt2 = $db2->prepare("SELECT * FROM clients WHERE id = " . $args['client']);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);

$response->getBody()->write("<h1>Create order for" . $a['firstname'] . " " . $a['lastname'] . "</h1><hr/>");
$response->getBody()->write('<form action="/orders/' . $args['client'] . '/create" method="post">');
$response->getBody()->write('<label for="id">Reference: </label>');

+ 7
- 0
src/DB/DB.php View File

@@ -10,4 +10,11 @@ class DB extends SQLite3
{
$this->open('./webshop.db');
}

public function getClientInfo($client) {
$stmt2 = $this->prepare("SELECT * FROM clients WHERE id = " . $client);
$res2 = $stmt2->execute();
$a = $res2->fetchArray(SQLITE3_ASSOC);
return $a;
}
}

Loading…
Cancel
Save