|
Assignment Fifteen
Updating Your Photo Database
|
|
Read chapter 11 in the Active Server Pages for Dummies book. Note that we use a different method to connect to the Database, because our server doesn't allow the use of the ODBC METHOD.(see Assignment 14)
This Assignment uses ASP, ( PHP for the file upload ), and Microsoft Access Database. The scenario is one where you want to store your photo images in the images directory and descriptions of the photo in the Access database. You will present the information using ASP to connect to the database and present the data in a web page from assignment 14.
The information is entered into a HTML Form and then the data record is added to the Access database. You need to create the ASP response page that loads the data into the Database.
You must use an external style sheet for text, backgrounds and images.
The HTML input Form will generate:
- A new row in the PhotoTable database for each input set of data.
- The ASP response page receives this data and inserts it into the Database table.
- You can download a sample of the PHP photo image upload File here upload.mdb, but you must rename it with a php extension instead of mdb
- You upload your photo images using the upload.php file listed below to your images directory. Because the database only has the file name stored in it.
The Upload file uses the following PHP code:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
// instead of $_FILES.
$uploaddir = 'images/'; //directory for your uploaded files
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
$img1_name = $uploadfile;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
?>
<h2>File Upload Successful!</h2>
Successfully Sent: <?php echo "$img1_name"; ?> ,<br />
<?
}
else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
?>
You can use this code to add a record set to the Database
' Establish a connection to the database
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_
Server.Mappath("db\photo.mdb"))
'___________________________________________________
' Create a recordset to hold the new entries.
Set rdset = Server.CreateObject("ADODB.Recordset")
rdset.Open "PhotoTable", Connection, adOpenForwardOnly, adLockOptimistic, adCmdTable
'___________________________________________________
' Use the Addnew/update methods to add the new Photo data.
rdset.AddNew
rdset( "name" ) = Request.Form( "name" )
rdset( "photo" ) = Request.Form( "photo" )
rdset( "wdata" ) = Request.Form( "wdata" )
rdset( "hdata" ) = Request.Form( "hdata" )
rdset( "description" ) = Request.Form( "description" )
rdset.Update
'__________________________________________________
' Close the recordset and dereference.
rdset.Close
Set rdset = Nothing
'__________________________________________________
' Display status
Response.Write "Database add completed successfully."
'__________________________________________________
' Close the connection and dereference.
Connection.Close
Set Connection = Nothing
See sample15.html for an example of the required assignment.
- You also are required to have a return link from your assignment to your index page.
- Link this assignment to your web site index page.
- Upload this assignment files (3 files) to your web space.
- You must also re upload your index file to your web space.