Server-side PHP Scripts


This application uses a database table, user, hosted by the server undcemcs01.und.edu. The table is accessed from the following two PHP scripts, using the GET and POST methods respectively:
CREATE TABLE user (
  name   VARCHAR(32) PRIMARY KEY,
  pword  VARCHAR(16) NOT NULL,
  role   VARCHAR(16) NOT NULL );

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

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

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

  // Connect to the database.
  if ( $conn->connect_error )
    die( 'Could not connect: ' . $conn->connect_error );

  // Retrieve the Android input.
  $name  = $_GET['name'];
  $pword = $_GET['pword'];

  // Compose and execute the query.
  $sql  = "SELECT role FROM user WHERE name='$name' AND pword='$pword'";
  if ( $result = $conn->query( $sql ) ) {
    $row  = $result->fetch_assoc( );
    $data = $row['role'];
  }

  // Return the data back to the Android.
  if ( $data )  echo $data;

  // Close the connection.
  $conn->close( );
?>
http://undcemcs01.und.edu/~wen.chen.hu/course/457/11/Android/LoginPost.php
<?php
  $username = "user.id@undcsmysql";
  $password = "password";
  $database = "schema";
  $host     = "undcsmysql.mysql.database.azure.com";
  $conn     = new mysqli( $host, $username, $password, $database );

  // Connect to the database.
  if ( $conn->connect_error )
    die( 'Could not connect: ' . $conn->connect_error );

  // Retrieve the Android input.
  $name  = $_POST['name'];
  $pword = $_POST['pword'];

  // Compose and execute the query.
  $sql  = "SELECT role FROM user WHERE name='$name' AND pword='$pword'";
  if ( $result = $conn->query( $sql ) ) {
    $row  = $result->fetch_assoc( );
    $data = $row['role'];
  }

  // Return the data back to the Android.
  if ( $data )  echo $data;

  // Close the connection.
  $conn->close( );
?>




      A soldier survived mustard gas in battle,    
      and then pepper spray by the police.    
      He’s now a seasoned veteran.