From 4b11857f6dc05a358cbd7d5d75141a003dbd6573 Mon Sep 17 00:00:00 2001 From: Samuel Wolff Date: Mon, 8 Jan 2024 11:14:17 +0100 Subject: [PATCH] diverses --- Controller/BenutzerController.php | 2 +- Controller/KindController.php | 2 +- Model/BenutzerModel.php | 22 +++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Controller/BenutzerController.php b/Controller/BenutzerController.php index 0dfc1dc..3c5d585 100644 --- a/Controller/BenutzerController.php +++ b/Controller/BenutzerController.php @@ -29,7 +29,7 @@ class BenutzerController } // Fügt einen Benutzer in die Datenbank hinzu - public function insertBenutzer($data) + public function writeBenutzer($data) { $result = $this->db->insertBenutzer($data); diff --git a/Controller/KindController.php b/Controller/KindController.php index 5aba8e7..fb744ac 100644 --- a/Controller/KindController.php +++ b/Controller/KindController.php @@ -1,7 +1,7 @@ $value) { - $sql .= " " . $index . " = :" . $index; + $sql .= " " . $index . " = :" . $index . ","; $params[":" . $index] = $value; } - $sql .= " WHERE id = :benutzerId;"; + $sql = substr($sql, 0, strlen($sql) - 1) . " WHERE id = :benutzerId;"; $params[":benutzerId"] = $elternId; @@ -40,6 +40,8 @@ class BenutzerModel extends Database $stmt = $pdo->prepare($sql); $stmt->execute($params); } catch (\PDOException $e) { + echo $sql; + echo json_encode($params); return false; } @@ -62,22 +64,24 @@ class BenutzerModel extends Database $params = array(); - $sql = "INSERT INTO Benutzer ("; + $sql = "INSERT INTO Benutzerkonto ("; foreach ($data as $index => $value) { $sql .= $index . ", "; - $params[":" + $index] = $index; + $params[":" . $index] = $index; } $sql = substr($sql, 0, strlen($sql) - 2) . ") VALUES ("; - foreach ($data as $value) { - $sql .= ":" . $value . " ,"; - $params[":" + $value] = $value; + foreach ($data as $index => $value) { + $sql .= ":" . $index . " ,"; + $params[":" . $index] = $value; } $sql = substr($sql, 0, strlen($sql) - 2) . ");"; + echo $sql; + try { $stmt = $pdo->prepare($sql); $stmt->execute($params);