databaseapplication.ppt

1,287 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,287
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

databaseapplication.ppt

  1. 1. 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
  2. 2. home.html <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Untitled Document</title> </li></ul><ul><li><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;> </li></ul><ul><li></head> </li></ul><ul><li><body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;> </li></ul><ul><li><p><a href=&quot;../home.htm&quot;>Main Home Page</a></p> </li></ul><ul><li><p><a href=&quot;display.php&quot;>View Records</a></p> </li></ul><ul><li><p><a href=“insertform.htm&quot;>Enter Records</a></p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  3. 3. insertform.htm <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Untitled Document</title> </li></ul><ul><li><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;> </li></ul><ul><li></head> </li></ul><ul><li><body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;> </li></ul><ul><li><p><a href=&quot;home.htm&quot;>home</a></p> </li></ul><ul><li><form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;insert.php&quot;> </li></ul><ul><li><p>Name </li></ul><ul><li><input type=&quot;text&quot; name=&quot;name&quot;> </li></ul><ul><li></p> </li></ul><ul><li><p>Age </li></ul><ul><li><input type=&quot;text&quot; name=&quot;age&quot;> </li></ul><ul><li></p> </li></ul><ul><li><p> </li></ul><ul><li><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;> </li></ul><ul><li></p> </li></ul><ul><li></form> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  4. 4. insert.php <ul><li><? </li></ul><ul><li>// script to display all the records in a table </li></ul><ul><li>// connection information </li></ul><ul><li>$hostName = &quot;dbm1.itc.virginia.edu&quot;; </li></ul><ul><li>$userName = “user&quot;; </li></ul><ul><li>$password = “password&quot;; </li></ul><ul><li>$dbName = “dbname&quot;; </li></ul><ul><li>// make connection to database </li></ul><ul><li>mysql_connect($hostName, $userName, $password) or die( &quot;Unable to connect to host $hostName&quot;); </li></ul><ul><li>mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;); </li></ul><ul><li>// Insert Data into table1 </li></ul><ul><li>$query = &quot;INSERT INTO table1 (name, age) VALUES ('$name', '$age')&quot;; </li></ul><ul><li>$result = mysql_query($query); </li></ul><ul><li>// Close the database connection </li></ul><ul><li>mysql_close(); </li></ul><ul><li>header(&quot;Location: home.htm&quot;); </li></ul><ul><li>?> </li></ul>
  5. 5. display.php (part 1) <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Data Display</title> </li></ul><ul><li></head> </li></ul><ul><li><body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;> </li></ul><ul><li><p><a href=&quot;home.htm&quot;>home</a></p> </li></ul><ul><li><p> </li></ul><ul><li><? </li></ul><ul><li>// script to display all the records in a table </li></ul><ul><li>// connection information </li></ul><ul><li>$hostName = &quot;dbm1.itc.virginia.edu&quot;; </li></ul><ul><li>$userName = “user&quot;; </li></ul><ul><li>$password = “password&quot;; </li></ul><ul><li>$dbName = “dbname&quot;; </li></ul><ul><li>// make connection to database </li></ul><ul><li>mysql_connect($hostName, $userName, $password) or die( &quot;Unable to connect to host $hostName&quot;); </li></ul><ul><li>mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;); </li></ul><ul><li>// Select all the fields in all the records of table1 </li></ul><ul><li>$query = &quot;SELECT * FROM table1 ORDER BY ID&quot;; </li></ul><ul><li>$result = mysql_query($query); </li></ul>
  6. 6. display.php (part 2) <ul><li>// Determine the number of employees </li></ul><ul><li>$number = mysql_numrows($result); </li></ul><ul><li>// Print the employee names </li></ul><ul><li>echo(&quot;There are $number employees:<p>&quot;); </li></ul><ul><li>$i = 0; </li></ul><ul><li>While ($i<$number) </li></ul><ul><li>{ </li></ul><ul><li>$ID = mysql_result($result,$i, &quot;ID&quot;); </li></ul><ul><li>$name = mysql_result($result,$i, &quot;name&quot;); </li></ul><ul><li>$age = mysql_result($result,$i, &quot;age&quot;); </li></ul><ul><li>echo(&quot;<a href=&quot;updateform.php?ID=$ID&name=$name&age=$age&quot;>Update</a> $name $age <a href=&quot;delete.php?ID=$ID&quot;>Delete</a><br>&quot;); </li></ul><ul><li>$i = $i + 1; </li></ul><ul><li>} </li></ul><ul><li>// Close the database connection </li></ul><ul><li>mysql_close(); </li></ul><ul><li>?> </li></ul><ul><li></p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  7. 7. updateform.php <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Untitled Document</title> </li></ul><ul><li><meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;> </li></ul><ul><li></head> </li></ul><ul><li><body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;> </li></ul><ul><li><p><a href=&quot;home.htm&quot;>home</a></p> </li></ul><ul><li><form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;update.php&quot;> </li></ul><ul><li><p>Name </li></ul><ul><li><input type=&quot;text&quot; name=&quot;name&quot; value=&quot;<? echo(&quot;$name&quot;)?>&quot;> </li></ul><ul><li><input type=&quot;hidden&quot; name=&quot;ID&quot; value=&quot;<? echo(&quot;$ID&quot;)?>&quot;> </li></ul><ul><li></p> </li></ul><ul><li><p>Age </li></ul><ul><li><input type=&quot;text&quot; name=&quot;age&quot; value=&quot;<? echo(&quot;$age&quot;)?>&quot;> </li></ul><ul><li></p> </li></ul><ul><li><p> </li></ul><ul><li><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;> </li></ul><ul><li></p> </li></ul><ul><li></form> </li></ul><ul><li><p>&nbsp;</p> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  8. 8. update.php <ul><li><? </li></ul><ul><li>// script to display all the records in a table </li></ul><ul><li>// connection information </li></ul><ul><li>$hostName = &quot;dbm1.itc.virginia.edu&quot;; </li></ul><ul><li>$userName = “user&quot;; </li></ul><ul><li>$password = “password&quot;; </li></ul><ul><li>$dbName = “dbname&quot;; </li></ul><ul><li>// make connection to database </li></ul><ul><li>mysql_connect($hostName, $userName, $password) or die( &quot;Unable to connect to host $hostName&quot;); </li></ul><ul><li>mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;); </li></ul><ul><li>// Select all the fields in all the records of table1 </li></ul><ul><li>$query = &quot;UPDATE table1 SET name = '$name', age = '$age' WHERE ID = '$ID'&quot;; </li></ul><ul><li>$result = mysql_query($query); </li></ul><ul><li>// Close the database connection </li></ul><ul><li>mysql_close(); </li></ul><ul><li>header(&quot;Location: display.php&quot;); </li></ul><ul><li>?> </li></ul>
  9. 9. delete.php <ul><li><? </li></ul><ul><li>// script to display all the records in a table </li></ul><ul><li>// connection information </li></ul><ul><li>$hostName = &quot;dbm1.itc.virginia.edu&quot;; </li></ul><ul><li>$userName = “user&quot;; </li></ul><ul><li>$password = “password&quot;; </li></ul><ul><li>$dbName = “dbname&quot;; </li></ul><ul><li>// make connection to database </li></ul><ul><li>mysql_connect($hostName, $userName, $password) or die( &quot;Unable to connect to host $hostName&quot;); </li></ul><ul><li>mysql_select_db($dbName) or die(&quot;Unable to select database $dbName&quot;); </li></ul><ul><li>// Select all the fields in all the records of table1 </li></ul><ul><li>$query = &quot;DELETE FROM table1 WHERE ID = '$ID'&quot;; </li></ul><ul><li>$result = mysql_query($query); </li></ul><ul><li>// Close the database connection </li></ul><ul><li>mysql_close(); </li></ul><ul><li>header(&quot;Location: display.php&quot;); </li></ul><ul><li>?> </li></ul>

×