Application Sketch home.htm delete.php updateform.php display.php insert.php insertform.htm update.php Data Base Hyperlink Information exchange with database Redirection Submit data via post Hyperlink with URL appended data
home.html Untitled Document Main Home Page View Records Enter Records
insertform.htm Untitled Document home Name Age
insert.php <? // script to display all the records in a table // connection information $hostName = "dbm1.itc.virginia.edu"; $userName = “user"; $password = “password"; $dbName = “dbname"; // make connection to database mysql_connect($hostName, $userName, $password) or die( "Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Insert Data into table1 $query = "INSERT INTO table1 (name, age) VALUES ('$name', '$age')"; $result = mysql_query($query); // Close the database connection mysql_close(); header("Location: home.htm"); ?>
display.php (part 1) Data Display home <? // script to display all the records in a table // connection information $hostName = "dbm1.itc.virginia.edu"; $userName = “user"; $password = “password"; $dbName = “dbname"; // make connection to database mysql_connect($hostName, $userName, $password) or die( "Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Select all the fields in all the records of table1 $query = "SELECT * FROM table1 ORDER BY ID"; $result = mysql_query($query);
display.php (part 2) // Determine the number of employees $number = mysql_numrows($result); // Print the employee names echo("There are $number employees: "); $i = 0; While ($i<$number) { $ID = mysql_result($result,$i, "ID"); $name = mysql_result($result,$i, "name"); $age = mysql_result($result,$i, "age"); echo(" Update $name $age Delete "); $i = $i + 1; } // Close the database connection mysql_close(); ?>
updateform.php Untitled Document home Name "> Age ">
update.php <? // script to display all the records in a table // connection information $hostName = "dbm1.itc.virginia.edu"; $userName = “user"; $password = “password"; $dbName = “dbname"; // make connection to database mysql_connect($hostName, $userName, $password) or die( "Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Select all the fields in all the records of table1 $query = "UPDATE table1 SET name = '$name', age = '$age' WHERE ID = '$ID'"; $result = mysql_query($query); // Close the database connection mysql_close(); header("Location: display.php"); ?>
delete.php <? // script to display all the records in a table // connection information $hostName = "dbm1.itc.virginia.edu"; $userName = “user"; $password = “password"; $dbName = “dbname"; // make connection to database mysql_connect($hostName, $userName, $password) or die( "Unable to connect to host $hostName"); mysql_select_db($dbName) or die("Unable to select database $dbName"); // Select all the fields in all the records of table1 $query = "DELETE FROM table1 WHERE ID = '$ID'"; $result = mysql_query($query); // Close the database connection mysql_close(); header("Location: display.php"); ?>