Re: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Bob

Bug report: You'll need to add another = to the if test..

if( $number == '0' ) $sql = "INSERT INTO $table_name( files ) VALUES(
> \"$files\" )";

Dumb mistake..

Bob

- Original Message -
From: "Bob" <[EMAIL PROTECTED]>
To: "jas" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, April 05, 2002 7:44 PM
Subject: Re: [PHP-DB] Stuck on db entry from select box...


> Okay, so I figured out why you might want to use UPDATE instead of SELECT.
> And I also found that no matter what I tried, UPDATE doesn't seem to be
able
> to UPDATE a table if there are no rows in it.. Otherwise it works fine..
So
> I found that I had to put an if test in that would check to see if the
table
> was empty and assign a different value to $sql than if the table wasn't
> empty. This is what I ended up with:
>
> 
> if( !$command ) main();
> if( $command == "goForIt" ) doTheDeed( $files );
> exit;
>
> function main()
> {
> $dir_name = "/home/httpd/html/database/images";
> $dir = opendir($dir_name);
> $file_list .= " ACTION=\"$PHP_SELF?command=goForIt\">
> $file_name";
>  while ($file_name = readdir($dir)) {
>   if (($file_name != ".") && ($file_name !="..")) {
>   $file_list .= " NAME=\"$file_name\">$file_name";
>   }
>  }
>  $file_list .= " VALUE=\"select\">";
>  closedir($dir);
>
> echo "$file_list";
> }
>
> function doTheDeed( $files )
> {
> $db_name = "phpTemp";
> $table_name = "fileList";
> $connection = mysql_connect("localhost", "oops", "didanyonesee") 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. Database said: " . mysql_error() );
> echo( "Executing Query. You submitted $files to
> the database.\n" );
> $getdata = mysql_query( "SELECT * FROM fileList" );
> $number = mysql_num_rows( $getdata );
> if( $number = '0' ) $sql = "INSERT INTO $table_name( files ) VALUES(
> \"$files\" )";
> else $sql = "UPDATE $table_name SET files = \"$files\"";
> $result = mysql_query($sql, $connection);
> $error = mysql_error();
> if( eregi( "uplicate", $error ) ) echo( "Sorry, $files is already in the
> database.\n" );
> else echo( "$files added to database successfully.\n" );
> echo( "Add another file?" );
> }
>
> ?>
>
> Later,
>
> Bob
>
> - Original Message -
> From: "Bob" <[EMAIL PROTECTED]>
> To: "jas" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Friday, April 05, 2002 5:43 PM
> Subject: RE: [PHP-DB] Stuck on db entry from select box...
>
>
> > I got it to work like this.. I don't know if you didn't want to use
INSERT
> > or something but it sticks the filename in the database table for me..
> >
> >  > $dir_name = "/home/httpd/html/database/images";
> > $dir = opendir($dir_name);
> > $file_list .= "
> > $file_name";
> >  while ($file_name = readdir($dir)) {
> >   if (($file_name != ".") && ($file_name !="..")) {
> >   $file_list .= " > NAME=\"$file_name\">$file_name";
> >   }
> >  }
> >  $file_list .= " > VALUE=\"select\">";
> >  closedir($dir);
> > ?>
> > within the page... I echo the results like so:
> > 
> > so far so good, now on the index_done.php3 my code is put into a require
> > statement and the required file code is as follows...
> >  > $db_name = "phpTemp";
> > $table_name = "fileList";
> > $connection = mysql_connect("localhost", "notme", "getyourown") 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. Database said: " . mysql_error() );
> > $sql = "INSERT INTO $table_name( files ) VALUES( \"$files\" )";
> > //$sql = "UPDATE $table_name SET files = \"$files\"";
> > $result = mysql_query($sql, $connection) or die ("Could not execute
query.
> > Database said: " .  mysql_error() );
> > ?>
> >
> > I changed the names of the database and table, stuff like that..
> >
> >
> > Personally, I 

Re: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Bob

Okay, so I figured out why you might want to use UPDATE instead of SELECT.
And I also found that no matter what I tried, UPDATE doesn't seem to be able
to UPDATE a table if there are no rows in it.. Otherwise it works fine.. So
I found that I had to put an if test in that would check to see if the table
was empty and assign a different value to $sql than if the table wasn't
empty. This is what I ended up with:


$file_name";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);

echo "$file_list";
}

function doTheDeed( $files )
{
$db_name = "phpTemp";
$table_name = "fileList";
$connection = mysql_connect("localhost", "root", "sinister") 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. Database said: " . mysql_error() );
echo( "Executing Query. You submitted $files to
the database.\n" );
$getdata = mysql_query( "SELECT * FROM fileList" );
$number = mysql_num_rows( $getdata );
if( $number = '0' ) $sql = "INSERT INTO $table_name( files ) VALUES(
\"$files\" )";
else $sql = "UPDATE $table_name SET files = \"$files\"";
$result = mysql_query($sql, $connection);
$error = mysql_error();
if( eregi( "uplicate", $error ) ) echo( "Sorry, $files is already in the
database.\n" );
else echo( "$files added to database successfully.\n" );
echo( "Add another file?" );
}

?>

Later,

Bob

- Original Message -
From: "Bob" <[EMAIL PROTECTED]>
To: "jas" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, April 05, 2002 5:43 PM
Subject: RE: [PHP-DB] Stuck on db entry from select box...


> I got it to work like this.. I don't know if you didn't want to use INSERT
> or something but it sticks the filename in the database table for me..
>
>  $dir_name = "/home/httpd/html/database/images";
> $dir = opendir($dir_name);
> $file_list .= "
> $file_name";
>  while ($file_name = readdir($dir)) {
>   if (($file_name != ".") && ($file_name !="..")) {
>   $file_list .= " NAME=\"$file_name\">$file_name";
>   }
>  }
>  $file_list .= " VALUE=\"select\">";
>  closedir($dir);
> ?>
> within the page... I echo the results like so:
> 
> so far so good, now on the index_done.php3 my code is put into a require
> statement and the required file code is as follows...
>  $db_name = "phpTemp";
> $table_name = "fileList";
> $connection = mysql_connect("localhost", "notme", "getyourown") 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. Database said: " . mysql_error() );
> $sql = "INSERT INTO $table_name( files ) VALUES( \"$files\" )";
> //$sql = "UPDATE $table_name SET files = \"$files\"";
> $result = mysql_query($sql, $connection) or die ("Could not execute query.
> Database said: " .  mysql_error() );
> ?>
>
> I changed the names of the database and table, stuff like that..
>
>
> Personally, I would do it like this:
>
> 
> if( !$command ) main();
> if( $command == "goForIt" ) doTheDeed( $files );
> exit;
>
> function main()
> {
> $dir_name = "/home/httpd/html/database/images";
> $dir = opendir($dir_name);
> $file_list .= " ACTION=\"$PHP_SELF?command=goForIt\">
> $file_name";
>  while ($file_name = readdir($dir)) {
>   if (($file_name != ".") && ($file_name !="..")) {
>   $file_list .= " NAME=\"$file_name\">$file_name";
>   }
>  }
>  $file_list .= " VALUE=\"select\">";
>  closedir($dir);
>
> echo "$file_list";
> }
>
> function doTheDeed( $files )
> {
> $db_name = "phpTemp";
> $table_name = "fileList";
> $connection = mysql_connect("localhost", "notme", "getyourown") 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. Database said: " . mysql_error() );
> $sql = "INSERT INTO $table_name( files ) VALUES( \"$files\" )";
> //$sql = "UPDATE $table_name SET files = \"$files\"";
> $result = mysql_query($sql, $connection);
> $error = mysql_error();
> if( eregi( "uplicate", $error ) ) echo( "Sorry, $files is already in the
> database." );
> else echo( "$files added to database successfully." );
> echo( "Add another file?" );
> }
>
> ?>
>
> But it is your project...
> Later,
>
> Bob Weaver
>


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




RE: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Bob

I got it to work like this.. I don't know if you didn't want to use INSERT
or something but it sticks the filename in the database table for me..


$file_name";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);
?>
within the page... I echo the results like so:

so far so good, now on the index_done.php3 my code is put into a require
statement and the required file code is as follows...


I changed the names of the database and table, stuff like that..


Personally, I would do it like this:


$file_name";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);

echo "$file_list";
}

function doTheDeed( $files )
{
$db_name = "phpTemp";
$table_name = "fileList";
$connection = mysql_connect("localhost", "notme", "getyourown") 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. Database said: " . mysql_error() );
$sql = "INSERT INTO $table_name( files ) VALUES( \"$files\" )";
//$sql = "UPDATE $table_name SET files = \"$files\"";
$result = mysql_query($sql, $connection);
$error = mysql_error();
if( eregi( "uplicate", $error ) ) echo( "Sorry, $files is already in the
database." );
else echo( "$files added to database successfully." );
echo( "Add another file?" );
}

?>

But it is your project...
Later,

Bob Weaver


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




Re: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Jas

Upon doing a print $sql before the mysql_querie I get this output;
UPDATE cm_index SET ad01_t=$files"Could not execute query. Please try again
later



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




Re: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Jas

Ok I made the changes you suggested and unfortunately I am getting the same
results... Could not execute query, I manually put entries into the tables
so that the update command would just overwrite the current contents.  Here
is my code this far, I think my problem (correct me if I am wrong) lies in
the fact that each of select boxes does not contain a unique name, needless
to say I am stuck:

";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);
?>
Select boxes are filled with files from specified folder... then echoed to
screen

Working fine... when user click on image using said select box it links to
this file, code is as follows:

Still getting could not execute query... sorry about not knowing where I am
going wrong but still new to these advanced functions.  Thanks in advance,
Jas



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




RE: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Rick Emery

I had a typo:

$sql = "UPDATE $table_name SET file_name=\"$files\"";

-Original Message-
From: Rick Emery [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 12:29 PM
To: 'Jas'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Stuck on db entry from select box...


jas,

Ya didn't do what I told you to do.  Now, do this:

";

$sql = "UPDATE $table_name SET file_name=\"$files\"";

-Original Message-
From: Jas [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 12:01 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Stuck on db entry from select box...


Ok here is my problem and where I am at this far, first thing I needed to do
is to read the contents of a directory and place the results into a select
box in a form (accomplished), now where I am stuck is passing the selection
from said select box to another script so it may be put into a mysql
database table... my code is as follows:

$file_name";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);
?>
within the page... I echo the results like so:

so far so good, now on the index_done.php3 my code is put into a require
statement and the required file code is as follows...

I think I need a new pair of eyes to review this and let me know where I am
going wrong, also on another note I don't want to put the file in the
database table I want to put the path to the file in the database table, any
help would be greatly appriciated. =)
Jas



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

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

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




RE: [PHP-DB] Stuck on db entry from select box...

2002-04-05 Thread Rick Emery

jas,

Ya didn't do what I told you to do.  Now, do this:

";

$sql = "UPDATE $table_name SET file_name=\$files\"";

-Original Message-
From: Jas [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 05, 2002 12:01 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Stuck on db entry from select box...


Ok here is my problem and where I am at this far, first thing I needed to do
is to read the contents of a directory and place the results into a select
box in a form (accomplished), now where I am stuck is passing the selection
from said select box to another script so it may be put into a mysql
database table... my code is as follows:

$file_name";
 while ($file_name = readdir($dir)) {
  if (($file_name != ".") && ($file_name !="..")) {
  $file_list .= "$file_name";
  }
 }
 $file_list .= "";
 closedir($dir);
?>
within the page... I echo the results like so:

so far so good, now on the index_done.php3 my code is put into a require
statement and the required file code is as follows...

I think I need a new pair of eyes to review this and let me know where I am
going wrong, also on another note I don't want to put the file in the
database table I want to put the path to the file in the database table, any
help would be greatly appriciated. =)
Jas



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

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