Sure, here's the code:
Code: Select all
<form action="act_addCategory.php" method="post" name="loginForm" id="loginForm">
<label for="CategoryName">Category Name:</label>
<input name="CategoryName" type="text" id="CategoryName" />
<label for="Image">Title Image:</label>
<input name="Image" type="file" id="Image" />
<input type="submit" value="Add Category" />
</form>
The contents of act_addCategory.php are as follows:
Code: Select all
<?php
// declare some relevant variables
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "thisDB";
$table = "category";
// this converts the form variables somehow
import_request_variables('p', 'p_');
// connect to database
$link = mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
// Set the correct file path for the image
$ImagePath = "_images/db_titles/" . basename($p_Image);
/*****************************/
/* add details to the database */
/*****************************/
// create the query to add data to the client_site table
$sqlquery = "INSERT INTO $table VALUES ('','" . $p_CategoryName . "','" . $ImagePath . "')";
// run the query
$result = mysql_query($sqlquery,$link);
/*****************************/
/* send user back to menu */
/*****************************/
header('Location: http://dare2.com.au/admin/siteAdmin.php');
?>
It's fair enough to say that the full path is not sent in a file upload, but as well as uploading the actual file (which I haven't gotten to yet) I need to put the file's name into the database. The file being uploaded is an image that relates to the category being created (the title graphic, in this case) and I want to put a reference in the database to where the image lives on the server so that when the category is referenced by the page it is a simple matter to call the appropriate graphic and add it to the page.
So even if I don't need to do this for the actual upload, I still need to get just the filename for the sake of entering it into the database.
Hope that makes things a little clearer.
Cheers,
Seona.