diff --git a/controllers/people.php b/controllers/people.php index 25758cd..e643ac5 100644 --- a/controllers/people.php +++ b/controllers/people.php @@ -7,7 +7,7 @@ if($_REQUEST['action'] === 'index'){ } else if ($_REQUEST['action'] === 'post'){ $requestBody = file_get_contents('php://input'); $body = json_decode($requestBody); - $newPerson = new Person($body->name, $body->age); + $newPerson = new Person(null, $body->name, $body->age); $allPeople = People::create($newPerson); diff --git a/database/sql/create.sql b/database/sql/create.sql index e69de29..be4df42 100644 --- a/database/sql/create.sql +++ b/database/sql/create.sql @@ -0,0 +1 @@ +INSERT INTO people (name, age) VALUES ($1, $2) diff --git a/models/person.php b/models/person.php index 8357769..a0a1fba 100644 --- a/models/person.php +++ b/models/person.php @@ -24,15 +24,10 @@ class People { return $people; } static function create($person){ - $people = array(); - $people[] = new Person('joni', 52); - $people[] = new Person('bob', 34); - $people[] = new Person('sally', 21); - $people[] = new Person('matt', 37); - - $people[] = $person; + $query = file_get_contents(__DIR__ . '/../database/sql/create.sql'); + $result = pg_query_params($query, array($person->name, $person->age)); - return $people; + return self::find(); } static function delete($index){ $people = array();