A page to illustrate MySql database use
<code>
<?php
//http://www.tutorialrepublic.com/php-tutorial/php-mysql-select-query.php
// MySQL host name, user name, password, database, and table for hareline table
$opts['hn'] = 'localhost';
$opts['un'] = 'root';
$opts['pw'] = 'password';
$opts['db'] = 'demo';
$opts['t1'] = 'persons';

$link=mysqli_connect($opts['hn'],$opts['un'],$opts['pw'],"");

if ($link===false) {die("Error: Could not connect - ".mysqli_connect_error());}
echo "Connect successful ".mysqli_get_host_info($link)."<br />";

//$sql="CREATE DATABASE ".$opts['db'];
//if (mysqli_query($link,$sql)) {echo "Database created successfully";}
//else {echo "Error: Unable to execute query $sql ".mysqli_error($link);}

$sql="USE ".$opts['db'];
if (mysqli_query($link,$sql)) {echo "Using database ".$opts['db']."<br />";} else {die("Cannot use ".$opts['db']." ".mysqli_error($link));}
//$sql="CREATE TABLE ".$opts['t1']." (
// id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
// first_name VARCHAR(30) NOT NULL,
// last_name VARCHAR(30) NOT NULL,
// email VARCHAR(70) NOT NULL UNIQUE,
// job_title INT NOT NULL)
// ";
//if (mysqli_query($link,$sql)) {echo "Created table ".$opts['t1']."<br />";} else {echo "Cannot create table ".$opts['t1']." ".mysqli_error($link)."<br />";}
// Create another table for job titles
//$sql="CREATE TABLE ".$opts['t2']." (
// id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
// title VARCHAR(30) NOT NULL UNIQUE)";
//if (mysqli_query($link,$sql)) {echo "Database created successfully";} else {echo "Error: Unable to execute query $sql ".mysqli_error($link);}

echo "<br />\n";
$sql="DESCRIBE ".$opts['t1'];

if ($result=mysqli_query($link,$sql)) {
 foreach ($result as $row) { echo $row["Field"]; echo "<br />"; }
} else {echo "$sql did not return any values";}
echo "<br /><hr /><br />\n";

// Attempt insert query execution
//$sql = "INSERT INTO ".$opts['t1']." (first_name, last_name, email,job_title) VALUES ('Peter', 'Parker', 'peterparker@mail.com',2)";
//if(mysqli_query($link, $sql)){echo "Records inserted successfully.";} else {echo "ERROR: Could not able to execute ".$sql." ".mysqli_error($link);}

// Attempt multiple insert query execution
//$sql = "INSERT INTO ".$opts['t1']." (first_name, last_name, email, job_title) VALUES
//         ('John', 'Rambo', 'johnrambo@mail.com', 3),
//         ('Clark', 'Kent', 'clarkkent@mail.com, 4),
//         ('John', 'Carter', 'johncarter@mail.com', 1),
//         ('Harry', 'Potter', 'harrypotter@mail.com', 2)";
//if(mysqli_query($link, $sql)){echo "Records added successfully.";} else {echo "ERROR: Could not able to execute ".$sql." ".mysqli_error($link);}

//HTML Form for use in inserting data
//<!DOCTYPE html>
//<html lang="en">
//<head>
//<meta charset="UTF-8">
//<title>Add Record Form</title>
//</head>
//<body>
//<form action="insert.php" method="post">
// <p>
//  <label for="firstName">First Name:</label>
//  <input type="text" name="first_name" id="firstName">
// </p>
// <p>
//  <label for="lastName">Last Name:</label>
//  <input type="text" name="last_name" id="lastName">
// </p>
// <p>
//  <label for="emailAddress">Email Address:</label>
//  <input type="text" name="email" id="emailAddress">
// </p>
// <input type="submit" value="Submit">
//</form>
//</body>
//</html>

// Then use this code to insert
// Escape user inputs for security
//$first_name = mysqli_real_escape_string($link, $_REQUEST['first_name']);
//$last_name = mysqli_real_escape_string($link, $_REQUEST['last_name']);
//$email = mysqli_real_escape_string($link, $_REQUEST['email']);
 
// attempt insert query execution
//$sql = "INSERT INTO ".$opts['t1']." (first_name, last_name, email) VALUES ('$first_name', '$last_name', '$email')";
//if(mysqli_query($link, $sql)){echo "Records added successfully.";} else {echo "ERROR: Could not able to execute ".$sql." ".mysqli_error($link);}

// ----------
// Using a Prepared Statement saves time for multiple INSERTs
// Prepare an insert statement
//$sql = "INSERT INTO ".$opts['t1']." (first_name, last_name, email) VALUES (?, ?, ?)";
 
//if($stmt = mysqli_prepare($link, $sql)){
// Bind variables to the prepared statement as parameters
// mysqli_stmt_bind_param($stmt, "sss", $first_name, $last_name, $email);
    
/* Set the parameters values and execute the statement again to insert another row */
//  $first_name = "Hermione";
//  $last_name = "Granger";
//  $email = "hermionegranger@mail.com";
//  mysqli_stmt_execute($stmt);
    
/* Set the parameters values and execute the statement to insert a row */
//  $first_name = "Ron";
//  $last_name = "Weasley";
//  $email = "ronweasley@mail.com";
//  mysqli_stmt_execute($stmt);

//  echo "Records inserted successfully.";} else {echo "ERROR: Could not prepare query: $sql. " . mysqli_error($link);}

// For the form above, modify to get the three variables then execute the Prepared Statement
//
// Set parameters
// $first_name = $_REQUEST['first_name'];
// $last_name = $_REQUEST['last_name'];
// $email = $_REQUEST['email'];
    
// Attempt to execute the prepared statement
// if(mysqli_stmt_execute($stmt)){echo "Records inserted successfully.";} else {echo "ERROR: Could not execute query: ".$sql." ".mysqli_error($link);};

// ----------

$sql="SELECT * FROM ".$opts['t1'];
// You can limit the number of rows returned by using 'LIMIT row_offset, row_count' in the SELECT statement above
if ($result=mysqli_query($link,$sql)) {
 if (mysqli_num_rows($result) > 0) {
  echo "<table>";
   echo "<tr>";
    echo "<th>id</th>";
    echo "<th>first_name</th>";
    echo "<th>last_name</th>";
    echo "<th>email</th>";
    echo "<th>job_title</th>";
   echo "</tr>";
  while ($row=mysqli_fetch_array($result)) {
   echo "<tr>";
    echo "<td>".$row['id']."</td>"; // or $row[0]
    echo "<td>".$row['first_name']."</td>"; // or $row[1]
    echo "<td>".$row['last_name']."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td>".$row['job_title']."</td>";
   echo "</tr>";
  }
  echo "</table>";
  // Free result set
  mysqli_free_result($result);
 } else {echo "No result matching your query were found\n";}
 
}
// Now do an INNER JOIN

$sql="SELECT a.id,a.first_name,a.last_name,a.email,b.title FROM ".$opts['t1']." a, ".$opts['t2']." b WHERE a.job_title=b.id";

if ($result=mysqli_query($link,$sql)) {
 if (mysqli_num_rows($result) > 0) {
  echo "<table>";
   echo "<tr>";
    echo "<th>id</th>";
    echo "<th>first_name</th>";
    echo "<th>last_name</th>";
    echo "<th>email</th>";
    echo "<th>job_title (join)</th>";
   echo "</tr>";
  while ($row=mysqli_fetch_array($result)) {
   echo "<tr>";
    echo "<td>".$row['id']."</td>"; // or $row[0]
    echo "<td>".$row['first_name']."</td>"; // or $row[1]
    echo "<td>".$row['last_name']."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td>".$row['title']."</td>";
   echo "</tr>";
  }
  echo "</table>";
  // Free result set
  mysqli_free_result($result);
 } else {echo "No result matching your query were found\n";}
}
// Close connection
mysqli_close($link);
?>
</code>