Ok this is an unusual problem, at least to a newbie like myself... I am
trying to develop a user form to select an image from a directory by use of
a select box that once the item is selected it will put that selection into
a db field and this part I have working fine, however now I will need to be
able to do something which I am not entirely clear on where to start...
1- I need to have the selection append the file path to the selected file...
i.e. http://localhost/images/file_name.jpg, so far it only puts
file_name.jpg into the database table.
My code is as follows:
Page 1- index.php (queries database to display current db contents and also
queries directory and places results into an array that is displayed in a
select box)

$dir_name = "/path/to/images/directory/on/server/";
$dir = opendir($dir_name);
$file_list .= "<p><FORM METHOD=\"post\" ACTION=\"index_done.php3\">
<SELECT NAME=\"files\">";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "<OPTION VALUE=\"$file_name\"
 $file_list .= "</SELECT><br><br><INPUT TYPE=\"submit\" NAME=\"submit\"
$table = "table_nae";
$dbh = mysql_connect('localhost','user_name','password') or die('Could not
connect to database, please try again later');
mysql_select_db('db_name') or die('Could not select database, please try
again later');
$record = @mysql_query("SELECT wel_area, ad01_t, ad01, ad02_t, ad02, ad03_t,
ad03, ad04_t, ad04, ad05_t, ad05, ad06_t, ad06 FROM $table",$dbh);
while ($row = mysql_fetch_array($record)) {
 list($wel_area, $ad01_t, $ad01, $ad02_t, $ad02, $ad03_t, $ad03, $ad04_t,
$ad04, $ad05_t, $ad05, $ad06_t, $ad06) = $row;

This echoes the resulting directory into my select box...
<? echo "$file_list"; ?>

And this will echo the existing db entry...
<img src="<?php echo $ad01_t; ?>" width="200" height="100" vspace="0"
hspace="0" border="0">

Ok so far so good, now the items that are selected from the drop box need to
somehow (this is where I am stuck append the file path, i.e. the complete
url to the db entry and I am not quite sure how to accomplish this, if
anyone has a tutorial or even an example to show me I can figure it out from
there... this is the piece of code I am using on the "index_done.php3" file.

$db_name = "db_name";
$table_name = "table_name";
$connection = @mysql_connect("localhost", "user_name", "password") or die
("Could not connect to database.  Please try again later.");
$db = @mysql_select_db("$db_name",$connection) or die ("Could not select
database table. Please try again later.");
$sql = "UPDATE $table_name SET ad01_t=\"$files"";
print $sql;
$result = @mysql_query($sql, $connection) or die ("Could not execute query.
Please try again later.");
Any help would be great...

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to