Server-side PHP Scripts


This application uses a database table, users, hosted by the server undcemcs01.und.edu. The following two PHP scripts are used to access the table:
CREATE TABLE  users (
   name      VARCHAR(32),
   password  VARCHAR(16),
   role      VARCHAR(16) );

INSERT INTO  users  VALUES(
   'Poke Mon', 'hush', 'admin' );

INSERT INTO  users  VALUES(
   'Mario', 'secret', 'user' );

INSERT INTO  users  VALUES(
   'Super Man', 'knock-knock', 'hacker' );
http://undcemcs01.und.edu/~wen.chen.hu/course/457/11/Android/login_get.php
<?php
  $username = $_GET['username'];
  $password = $_GET['password'];
  $host     = "undcsmysql.mysql.database.azure.com";
  $conn     = new mysqli( $host, "user.id@undcsmysql", "passwd", "schema" );

  if ( $conn->connect_error )
    die( 'Could not connect to MySQL: ' . $conn->connect_error );
  else {
    $sql  = "SELECT role FROM users WHERE ";
    $sql .= "name='$username' AND password='$password'";
    if ( $result = $conn->query( $sql ) ) {
      $row  = $result->fetch_assoc( );
      $data = $row['role'];
    }
    if ( $data )  echo $data;
    $conn->close( );
  }
?>
http://undcemcs01.und.edu/~wen.chen.hu/course/457/11/Android/login_post.php
<?php
  $username = $_POST['username'];
  $password = $_POST['password'];
  $host     = "undcsmysql.mysql.database.azure.com";
  $conn     = new mysqli( $host, "user.id@undcsmysql", "passwd", "schema" );

  if ( $conn->connect_error )
    die( 'Could not connect to MySQL: ' . $conn->connect_error );
  else {
    $sql  = "SELECT role FROM users WHERE ";
    $sql .= "name='$username' AND password='$password'";
    if ( $result = $conn->query( $sql ) ) {
      $row  = $result->fetch_assoc( );
      $data = $row['role'];
    }
    if ( $data )  echo $data;
    $conn->close( );
  }
?>