[PHP-DB] If statement for sql statement

2002-04-09 Thread jas

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 .= pFORM 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 .= /SELECTbrbrINPUT 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\;




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




Re: [PHP-DB] If statement for sql statement

2002-04-09 Thread Jason Wong

On Wednesday 10 April 2002 12:32, jas wrote:
 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:

[snip]

 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\;

Am I missing something? Psuedo-code:


 if ($file_name != '--') {
   $sql = UPDATE ;
   $result = $mysql_query($sql); 
   etc;
   etc; }
 else {
   don't even need an else!
 }


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *


/*
The sun never sets on those who ride into it.
-- RKO
*/

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