Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- class Test{
- public function __construct(){
- if( $this -> checkAPIKey()){
- }
- $this->reserveSeat();
- }
- public function connect() {
- // db vars stuff
- $servername = 'localhost';
- $username = 'root';
- $password = '';
- $dbname = "i";
- // db connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // check connection
- if ($conn->connect_error) {
- die('Connection failed: ' . $conn->connect_error);
- }
- return $conn;
- }
- public function checkAPIKey(){
- if( isset( $_POST['api_key']) && !empty($_POST['api_key']) ) {
- $db = $this -> connect();
- $query = "SELECT * FROM `vh_keys` where `api_key` = '" . $_POST['api_key'] . "'";
- $result = mysqli_query($db, $query);
- if (mysqli_num_rows($result) == 0) {
- die( 'Invalid API key' );
- }
- return true;
- }
- }
- public function reserveSeat(){
- //check seat_rand
- if( $_POST['seat_rand'] == false ) {
- $db = $this -> connect();
- // get random id
- $query_select = "SELECT `id` FROM `vh_seats` where `user_id` is NULL ORDER BY RAND() LIMIT 1";
- $result = mysqli_query($db, $query_select);
- $row = $result->fetch_assoc();
- //insert with randomn id;
- $query_update = "UPDATE `vh_seats` SET `user_id` = '1', `date` ='CURDATE()' WHERE `vh_seats`.`id` = " . $row['id'] . ";";
- $result = mysqli_query($db, $query_update);
- }
- }
- public function return_seats(){
- $db = $this -> connect();
- $query = "SELECT * FROM `vh_seats` where `user_id` is NULL";
- $result = mysqli_query($db, $query);
- if (mysqli_num_rows($result) > 0) {
- while($row = mysqli_fetch_assoc($result)) {
- $json[] = $row;
- }
- } else {
- echo "0 results";
- }
- echo json_encode($json);
- }
- }
- $t = new Test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement