-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated backend for multi user effect
Also created api for routing data to server
- Loading branch information
Showing
7 changed files
with
299 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,91 @@ | ||
<?php | ||
include 'settings.php'; | ||
|
||
// Create connection | ||
$sql = new mysqli($servername, $username, $password, $db); | ||
|
||
|
||
//simple script to store and retrieve multiple student answers... | ||
session_start(); | ||
$r='{"errMsg":"No Action Provided"}'; | ||
if(!isset($_SESSION['saa'])) $_SESSION['saa']= array(); | ||
$saa=$_SESSION['saa']; | ||
$postdata = file_get_contents("php://input"); | ||
$request = json_decode($postdata); | ||
if(!isset($request->action)) { | ||
echo $r. var_dump($request); | ||
if(!isset($_REQUEST['action'])) { | ||
echo $r. var_dump($_REQUEST); | ||
exit(); | ||
} | ||
switch($request->action){ | ||
switch($_REQUEST['action']){ | ||
case 'save': | ||
if(!isset($request->name)) $r='{"errMsg":"No name"}'. var_dump($request); | ||
if(!isset($request->name)) $r='{"errMsg":"No name"}'; | ||
else { | ||
$_SESSION['saa'][$request->name]=json_encode($request->value); | ||
$r='{"data":'.$_SESSION['saa'][$request->name].'}'; | ||
if(isset($request->id)){ | ||
/* prepared statements didnt work on production server?? | ||
$q="update bp_answers set name=?, value=? where id=?"; | ||
$stmt=$sql->prepare($q); | ||
$stmt->bind_param("ssi", $request->name, json_encode($request->value), $request->id); | ||
$stmt->execute(); | ||
*/ | ||
$sql->query("update bp_answers set name='".$sql->real_escape_string($request->name)."', value='".$sql->real_escape_string(json_encode($request->value))."' where id=".$sql->real_escape_string($request->id).""); | ||
} | ||
else{ | ||
/* prepared statements didnt work on production server?? | ||
$q="insert into bp_answers (name,value) values (?,?)"; | ||
$stmt=$sql->prepare($q); | ||
$stmt->bind_param("ss", $request->name, json_encode($request->value)); | ||
$stmt->execute(); | ||
*/ | ||
$sql->query("insert into bp_answers (name, value) values ('".$sql->real_escape_string($request->name)."', '".$sql->real_escape_string(json_encode($request->value))."')"); | ||
$request->id=$sql->insert_id; | ||
} | ||
$r= json_encode($request); | ||
} | ||
break; | ||
case 'fetch': | ||
if(isset($request->name)&&isset($saa[$request->name])) $r='{"data":'.$saa[$request->name].'}'; | ||
if(isset($request->name)){ | ||
/* prepared statements didnt work on production server?? | ||
$stmt=$sql->prepare("select * from bp_answers where name=?"); | ||
$stmt->bind_param("s",$request->name); | ||
$stmt->execute(); | ||
$stmt->bind_result($request->id, $request->name, $request->value); | ||
if($stmt->fetch()){ | ||
$request->value= json_decode($request->value); | ||
$r= json_encode($request); | ||
} | ||
* | ||
*/ | ||
$res=$sql->query("select * from bp_answers where name ='".$sql->real_escape_string($request->name)."'"); | ||
if($row=$res->fetch_assoc()){ | ||
$row['value']= json_decode($row['value']); | ||
$r= json_encode ($row); | ||
} | ||
else $r='{"errMsg":"No data for that name"}'; | ||
} | ||
else $r='{"errMsg":"No data for that name"}'; | ||
break; | ||
case 'fetchAll': | ||
$sep="";$r=""; | ||
foreach ($saa as $nm=>$data){ | ||
$r.=$sep.$data; | ||
$sep=", "; | ||
$r=""; | ||
/* prepared statements didnt work on production server?? | ||
$stmt=$sql->prepare("select value from bp_answers"); | ||
$stmt->execute(); | ||
$stmt->bind_result($value); | ||
$sep=""; | ||
while($stmt->fetch()){ | ||
$r.=$sep.$value; | ||
$sep=","; | ||
} | ||
$r="[".$r."]"; | ||
* | ||
*/ | ||
$sep=""; | ||
$res=$sql->query("select value from bp_answers where value is not null and value !='' "); | ||
while($row=$res->fetch_assoc()){ | ||
$r.=$sep.$row['value']; | ||
$sep=","; | ||
} | ||
$r= "[".$r."]"; | ||
break; | ||
case 'clearAll': | ||
unset($_SESSION['saa']); | ||
$stmt=$sql->query("delete from bp_answers"); | ||
$r='{"msg":"OK"}'; | ||
} | ||
echo $r; | ||
|
||
|
||
$sql->close(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
$servername = "dotals.net"; | ||
$username = "dotalsne_balance"; | ||
$password = "!qoHK[5[9fS3"; | ||
$db='dotalsne_balancepoint'; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.