persist in database sample form inputs and show the list of previously entered prompts when displaying form's result
parent
b1da73b743
commit
bd8d8a3f61
@ -1,12 +1,15 @@
|
||||
import ReactDOM from "react-dom/client";
|
||||
import React from "react";
|
||||
|
||||
|
||||
export default function DisplayResults({password, username}: any) {
|
||||
export default function DisplayResults({results}: { results: { name: string, description: string }[] }) {
|
||||
const list = results.map(({name, description}) =>
|
||||
<div>
|
||||
<p>username: {name}</p>
|
||||
<p>description: {description}</p>
|
||||
</div>
|
||||
)
|
||||
return (
|
||||
<div>
|
||||
<p>username: {username}</p>
|
||||
<p>password: {password}</p>
|
||||
{list}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Gateway;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
/**
|
||||
* A sample gateway, that stores the sample form's result.
|
||||
*/
|
||||
class FormResultGateway {
|
||||
|
||||
private PDOStatement $insertion_stmnt;
|
||||
private PDOStatement $list_stmnt;
|
||||
|
||||
public function __construct(PDO $pdo)
|
||||
{
|
||||
$this->insertion_stmnt = $pdo->prepare("INSERT INTO FormEntries VALUES (:name, :description)");
|
||||
$this->list_stmnt = $pdo->prepare("SELECT * FROM FormEntries");
|
||||
}
|
||||
|
||||
|
||||
function insert(string $username, string $description) {
|
||||
$this->insertion_stmnt->bindValue(":name", $username, PDO::PARAM_STR);
|
||||
$this->insertion_stmnt->bindValue(":description", $description, PDO::PARAM_STR);
|
||||
|
||||
$this->insertion_stmnt->execute();
|
||||
}
|
||||
|
||||
function listResults(): array {
|
||||
$this->list_stmnt->execute();
|
||||
return $this->list_stmnt->fetchAll();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue