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/12/Android/LoginGet.php
<?php
  $host     = "undcemmysql.mysql.database.azure.com";
  $username = "your_id";
  $database = "your_db";
  $password = "your-pw";
  
  // Initializing MySQLi
  $conn     = mysqli_init( );

  // Creating an SSL connection
  mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );

  // Opening a new connection to the MySQL server
  mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );

  // Connect to the database.
  if ( $conn->connect_errno )
    die( 'Failed to connect to MySQL: ' . $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 database connection.
  $conn->close( );
?>
http://undcemcs01.und.edu/~wen.chen.hu/course/457/12/Android/LoginPost.php
<?php
  $host     = "undcemmysql.mysql.database.azure.com";
  $username = "your_id";
  $database = "your_db";
  $password = "your-pw";
  
  // Initializing MySQLi
  $conn     = mysqli_init( );

  // Creating an SSL connection
  mysqli_ssl_set( $conn, NULL, NULL, "DigiCertGlobalRootCA.crt.pem", NULL, NULL );

  // Opening a new connection to the MySQL server
  mysqli_real_connect( $conn, $host, $username, $password, $database, 3306 );

  // Connect to the database.
  if ( $conn->connect_errno )
    die( 'Failed to connect to MySQL: ' . $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 database connection.
  $conn->close( );
?>




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