If statement for sql statement
| From: | jas | Date: | Wed, 10 Apr 2002 04:32:32 +0000 |
| Subject: | If statement for sql statement | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-18361@lists.php.net to get a copy of this message | ||
Ok here is my question... I have a form that reads the contents of a
directory, places the resulting files into a select box within a form for
further processing, code is as follows:
<?php
$dir_name = "/virtual/path/to/images/directory/";
$dir = opendir($dir_name);
$file_list .= "<p><FORM METHOD=\"post\"
ACTION=\"index_done.php3\">
<SELECT NAME=\"files\"><OPTION VALUE=\"----------\"
NAME=\"----------\">----------</OPTION>";
while ($file_name = readdir($dir)) {
if (($file_name != ".") && ($file_name !="..")) {
$file_list .= "<OPTION VALUE=\"$file_name\"
NAME=\"$file_name\">$file_name</OPTION>";
}
}
$file_list .= "</SELECT><br><br><INPUT TYPE=\"submit\"
NAME=\"submit\"
VALUE=\"select\"></FORM></p>";
closedir($dir);
?>
This portion works great... now on index_done.php3 it takes the resulting
selection and places it into the db table, code is as follows:
<?php
$file_var = "http://localhost/images/";
$db_name = "database";
$table_name = "image_path";
$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 image01_t=\"$file_var$files\"";
$result = @mysql_query($sql, $connection) or die ("Could not execute query.
Please try again later.");
?>
What I need to know is if there is a way to create an if statement that
would either update or not update a selected field in the database. Below
is a piece I would assume would work however I am not sure of the mysql
command to not update anything. Any help would be great.
Jas
if( $file_name = '----------' ) $sql = "dont update table";
else $sql = "UPDATE $table_name SET image01_t = \"$files\"";