Skip to content

Instantly share code, notes, and snippets.

@rugbyprof
Last active February 14, 2020 02:05
Show Gist options
  • Save rugbyprof/f85fd689c06f84289971 to your computer and use it in GitHub Desktop.
Save rugbyprof/f85fd689c06f84289971 to your computer and use it in GitHub Desktop.
over simple php backend
<?php
$_POST['action'] = 'select';
// $_POST['First'] = 'Mark';
// $_POST['Last'] = 'Twain';
// $_POST['Thumb'] = '';
// $_POST['Lat'] = '33.12343';
// $_POST['Lon'] = '-98.234563';
// $_POST['Sex'] = 'M';
// $_POST['Phone'] = '9403687777';
// $_POST['Email'] = '[email protected]';
// $_POST['Busy'] = '0';
// $_POST['LoggedIn'] = '1';
if(isset($_POST['action'])){
$db = new PDO('mysql:host=localhost;dbname=mobile_web;charset=utf8', 'mobile', 'mobile');
switch($_POST['action']){
//Adding a new user into our most splendid spy program
case "insert":
$sql = "SELECT MAX(Id) as Max FROM Active_Users";
$rows = $db->query($sql);
$result = $rows->fetchAll(PDO::FETCH_ASSOC);
$max = $result[0]['Max'] + 1;
$sql = "INSERT INTO `mobile_web`.`Active_Users` (`Id`, `First`, `Last`, `Thumbnail`, `Lat`, `Lon`, `Sex`, `Phone`, `Email`, `Busy`, `LoggedIn`)
VALUES ('{$max}', '{$_POST['First']}',
'{$_POST['Last']}', '{$_POST['Thumb']}',
'{$_POST['Lat']}', '{$_POST['Lon']}',
'{$_POST['Sex']}', '{$_POST['Phone']}',
'{$_POST['Email']}', '{$_POST['Busy']}', '{$_POST['LoggedIn']}');";
$db->query($sql);
break;
//Switching a user from either logged in or busy to vice versa.
case "update":
$db->query("UPDATE Active_Users SET LoggedIn = '1' WHERE ");
break;
//Remove a user completely from our spy program
case "delete":
break;
//Getting all logged in users who are not busy
case "select":
$rows = $db->query("SELECT * FROM Active_Users WHERE LoggedIn = '1'");
$result = $rows->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
break;
}
}else{
echo "Error:!!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment