From 12f6cc3a6f90a67c1d922dd3d46a368b1066dee1 Mon Sep 17 00:00:00 2001 From: Julien Sere Date: Sat, 22 Jan 2011 11:50:29 +0000 Subject: Implémentation de user et game. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2011-usi/trunk@8 db941bf7-0cb3-4dda-9634-87faf64f93a7 --- app/v1_php/api/game/form.html | 22 ++++++++++++++++++++++ app/v1_php/api/game/index.php | 28 ++++++++++++++-------------- app/v1_php/api/mysql_connect.inc.php | 5 ++++- app/v1_php/api/user/form.html | 2 +- app/v1_php/api/user/index.php | 10 ++++------ 5 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 app/v1_php/api/game/form.html (limited to 'app/v1_php/api') diff --git a/app/v1_php/api/game/form.html b/app/v1_php/api/game/form.html new file mode 100644 index 0000000..ed4ad72 --- /dev/null +++ b/app/v1_php/api/game/form.html @@ -0,0 +1,22 @@ + + + + + +
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/app/v1_php/api/game/index.php b/app/v1_php/api/game/index.php index a8658ac..154d905 100644 --- a/app/v1_php/api/game/index.php +++ b/app/v1_php/api/game/index.php @@ -2,7 +2,6 @@ /* Table Game -Unique key : */ require_once("../mysql_connect.inc.php"); @@ -10,14 +9,14 @@ require_once("../mysql_connect.inc.php"); $authentication_key=$_POST['authentication_key']; if ($authentication_key !== "azertyuiop") { - // header 401, "Clé d'authentification non reconnue" - echo "401, Clé d'authentification non reconnue\n"; + header("Clé d'authentification non reconnue", true, 401); + exit(); } -$parameters=json_decode($_POST['parameters']); +$parameters=json_decode($_POST['parameters'], true); if ( !is_array($parameters) || !is_numeric($parameters['longpollingduration']) ){ - // header 400, "Erreur" - echo "header 400, Erreur paramètres\n"; + header("Erreur paramètres", true, 400); + exit(); } $longpollingduration=$parameters['longpollingduration']; @@ -26,19 +25,20 @@ $questiontimeframe=$parameters['questiontimeframe']; $nbquestions=$parameters['nbquestions']; if ( $parameters['flushusertable'] === "true" ) { - $req="TRUNCATE TABLE User;" - $res=mysql_query($req); + $req="TRUNCATE TABLE User;"; + mysql_query($req); //TODO check result } -$req="INSERT INTO Game (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)"; +$req="INSERT INTO Game VALUES (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)"; $res=mysql_query($req); -if ( mysql_num_rows() === 1 ) { - //TODO header 201, "OK : CREATED" - echo "header 201, OK : CREATED\n"; + +echo mysql_error(); + +if ( $res===true && mysql_affected_rows() === 1 ) { + header("OK : CREATED", true, 201); } else { - // header 400, "Erreur" - echo "header 400, Erreur insertion SQL\n"; + header("erreur", true, 400); } ?> diff --git a/app/v1_php/api/mysql_connect.inc.php b/app/v1_php/api/mysql_connect.inc.php index 0414480..9cd7211 100644 --- a/app/v1_php/api/mysql_connect.inc.php +++ b/app/v1_php/api/mysql_connect.inc.php @@ -3,9 +3,12 @@ $mysqlcon=mysql_connect("localhost", "usi2011", "usi2011"); $res=mysql_select_db("usi2011"); -if ( ! is_resource($mysqlcon) || $res !== 0) { + +if ( ! is_resource($mysqlcon) || $res !== true) { //header 400, Erreur connexion SQL echo "Erreur connexion SQL\n"; exit(); + } + ?> diff --git a/app/v1_php/api/user/form.html b/app/v1_php/api/user/form.html index a01d2dd..fb2fc67 100644 --- a/app/v1_php/api/user/form.html +++ b/app/v1_php/api/user/form.html @@ -3,7 +3,7 @@ -
+
diff --git a/app/v1_php/api/user/index.php b/app/v1_php/api/user/index.php index 495bd2a..3b27b03 100644 --- a/app/v1_php/api/user/index.php +++ b/app/v1_php/api/user/index.php @@ -12,14 +12,12 @@ $lastname=mysql_real_escape_string($_POST['lastname']); $mail=mysql_real_escape_string($_POST['mail']); $password=mysql_real_escape_string($_POST['password']); -$req="INSERT INTO User (NULL,'$firstname', '$lastname', '$mail', '$password')"; +$req="INSERT INTO User VALUES (NULL, '$firstname', '$lastname', '$mail', '$password')"; $res=mysql_query($req); -if ( mysql_num_rows() === 1 ) { - //TODO header 201, "OK : CREATED" - echo "header 201, OK : CREATED\n"; +if ( $res===true && mysql_affected_rows() === 1 ) { + header("OK : CREATED", true, 201); } else { - // header 400, "Erreur" - echo "header 400, Erreur\n"; + header("erreur", true, 400); } ?> -- cgit v1.2.3