diff --git a/start.php b/start.php index e91bf69..62360fe 100644 --- a/start.php +++ b/start.php @@ -15,19 +15,22 @@ $length = (($length === '0') || ($length && gettype(+$length) == 'integer')) ? +$_GET['length'] : 10; $database = new Database(); $questions_count = $database->query('SELECT COUNT(*) FROM "Questions"')['data'][0]['count']; + + function start_game($length) { + print 'Ich bin die Funktion.'; + } + if($length == 0) { $error = 12101; } else if($length > $questions_count) { $error = 12102; $values = array($questions_count); } else { - /* - * if game for user exists then delete - * create new game for user - */ if($database->query('SELECT EXISTS (SELECT 1 fROM "Games" WHERE "ID" = $1)', array($uid)) == 't') { - + $database->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid)); } + $database->query('INSERT INTO "Games" ("ID") VALUES ($1)', array($uid)); + $this->create_game($length); } $response = Database::create_response($data, $error, $values); print $response;