PHP and MySQL Library Tutorial

General
Site Root
Database Home
Conect to MySQL
MySQL_Login.php
nav.php
dump.php

Clean Up resets the
database to contain
a few sensible
records.

Download Tutorial

Database
Create
Drop

Person Table
Create
Drop

Insert
Delete
Update
Search
Date-Search

Row Dump
Better View 
Table View 
Form View

Book Table
Create
Drop

Insert
Delete
Update
Search




Table View 
Form View

Loan Table
Create
Drop

Insert
Delete

Search




Table View

Documentation
Data Requirements
User Interface Design
Entity Relationship Diagrams
Data Flow Diagrams
Data Dictionary
Implementation Notes
Table Designs
Goals, Testing and Appraisal

Note - Create, Drop and Clean Up would be hidden on a real life system.
Contact - nbauers at samphire dot demon dot co dot uk
Copyright © - You may use and reproduce this material in a "not for profit" setting.

SELECT * FROM 
  book 
WHERE
  book_title LIKE '%%' 
OR 
  author LIKE '%%'
Enter all or part of the title or author's name

Accession Number

ISBN

Book Title

Author

Publisher

1 9780140303189 Jack Holborn Leon Garfield Penguin Books
2 9780450058867 Chapter House Dune Frank Herbert New English Library
3 9780450058867 Chapter House Dune Frank Herbert New English Library
4 9780340186119 The Hollow Hills Mary Stewart Coronet Books

Code Listing : bookSearch.php

<?php
  $search_text = htmlentities($_POST['search_text']);
  
  require "../MySQL_Login.php";    // Contains host, username, password, and database
  $link   = mysql_connect($host, $user, $password) or die(mysql_error());
  mysql_select_db ($database) or die(mysql_error());
  $sql = 
"SELECT * FROM 
  book 
WHERE
  book_title LIKE '%$search_text%' 
OR 
  author LIKE '%$search_text%'";
	       
  $result = mysql_query($sql, $link) or die(mysql_error());
  
  mysql_close($link);
?>

<html>
<head>
<title>Search for a Book</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php
  include "nav.php";
  echo"<font size=\"+2\"><b><pre>$sql</pre></b></font>";
?>

<form name="form1" method="post" action="">
  <table border="1" cellpadding="4" cellspacing="0">
    <tr> 
      <td><div align="right">Enter all or part of the title or author's name</div></td>
      <td>
        <input name="search_text" type="text" id="search_text" 
         value="<?php echo $search_text;  ?>">
      </td>
    </tr>
    <tr> 
      <td colspan="2">
        <div align="right"> 
          <input type="submit" name="Submit" value="Submit">
	</div>
      </td>
    </tr>
  </table>
</form>

  <table border="1" cellspacing="0" cellpadding="4">
    <tr>
      <td><h3>Accession Number</h3></td>
      <td><h3>ISBN</h3></td>
      <td><h3>Book Title</h3></td>
      <td><h3>Author</h3></td>
      <td><h3>Publisher</h3></td>
    </tr>

<?php 
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    {
      echo "    <tr>\n";
      echo "      <td>" . $row['accession_num'] . "</td>\n";
      echo "      <td>" . $row['isbn']          . "</td>\n";
      echo "      <td>" . $row['book_title']    . "</td>\n";
      echo "      <td>" . $row['author']        . "</td>\n";
      echo "      <td>" . $row['publisher']     . "</td>\n";
      echo "    </tr>\n";
    }
?>
    
  </table>

<?php
  include "dump.php";
  dump_page(basename($_SERVER[SCRIPT_FILENAME]));  // Display the code of this page
?>

</body>
</html>