Source of: example.6-1.php

<?
/*
Source code example for Web Database Applications

Unless otherwise stated, the source code distributed with this book can be
redistributed in source or binary form so long as an acknowledgment appears
in derived source files.
The citation should list that the code comes from Hugh E.
Williams and David Lane, "Web Database Application with PHP and MySQL"
published by O'Reilly & Associates.
This code is under copyright and cannot be included in any other book,
publication, or educational product without permission from O'Reilly &
Associates.
No warranty is attached; we cannot take responsibility for errors or fitness
for use.
*/
?>
<!DOCTYPE HTML PUBLIC 
               "-//W3C//DTD HTML 4.0 Transitional//EN"
               "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Insert a Region</title>
</head>
<body>
<?php
  
include 'db.inc';
  include 
'error.inc';

  
// Test for user input
  
if (empty($regionName) || empty($description))
  {
?>
    <form method="GET" action="example.6-1.php">
    Region_name:
    <br><input type="text" name="regionName" size=80>
    <br>Description:
    <br><textarea name="description" rows=4 cols=80></textarea>
    <br><input type="submit">
    </form>
<?php    
  
}
  else 
  {
     if (!(
$connection = @ mysql_connect($hostName
                                       
$username
                                       
$password)))
        die(
"Could not connect to database");

     if (!
mysql_select_db($databaseName$connection))
        
showerror();

       
$insertQuery "INSERT INTO region VALUES (NULL, " .
                    
"\"" $regionName "\", " .
                    
"\"" $description "\", " .
                    
"NULL)";

     if ((@ 
mysql_query ($insertQuery,
                          
$connection))
              && @ 
mysql_affected_rows() == 1)
        echo 
"<h3>Region successfully inserted</h3>";
     else
        
showerror();
  } 
// if else empty()
?>
</body>
</html>


© 2000--2001 Hugh E. Williams and David Lane.
Valid HTML 4.01!