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:
>
> <?php
>
> if( !$command ) main();
> if( $command == "goForIt" ) doTheDeed( $files );
> exit;
>
> function main()
> {
> $dir_name = "/home/httpd/html/database/images";
> $dir = opendir($dir_name);
> $file_list .= "<p><FORM METHOD=\"post\"
> ACTION=\"$PHP_SELF?command=goForIt\">
> <SELECT NAME=\"files\">$file_name";
>  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);
>
> 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 <font color=maroon>$files</font> to
> the database.<br>\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.<br><br>\n" );
> else echo( "$files added to database successfully.<br><br>\n" );
> echo( "<a href=\"javascript:history.back();\">Add another file?</a>" );
> }
>
> ?>
>
> 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..
> >
> > <?php
> > $dir_name = "/home/httpd/html/database/images";
> > $dir = opendir($dir_name);
> > $file_list .= "<p><FORM METHOD=\"post\" ACTION=\"$PHP_SELF\">
> > <SELECT NAME=\"files\">$file_name";
> >  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);
> > ?>
> > within the page... I echo the results like so:
> > <? echo "$file_list"; ?>
> > 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...
> > <?php
> > $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:
> >
> > <?php
> >
> > if( !$command ) main();
> > if( $command == "goForIt" ) doTheDeed( $files );
> > exit;
> >
> > function main()
> > {
> > $dir_name = "/home/httpd/html/database/images";
> > $dir = opendir($dir_name);
> > $file_list .= "<p><FORM METHOD=\"post\"
> > ACTION=\"$PHP_SELF?command=goForIt\">
> > <SELECT NAME=\"files\">$file_name";
> >  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);
> >
> > 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.<br><br>" );
> > else echo( "$files added to database successfully.<br><br>" );
> > echo( "<a href=\"javascript:history.back();\">Add another file?</a>" );
> > }
> >
> > ?>
> >
> > 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

Reply via email to