Below is the output and code for my problem.  When the database gets read,
it returns 0 rows.  When it writes, it says it can't because of duplicate
entry.  FLD_FileName and FDL_Path are the Primary key.

Two questions, what I am doing wrong and is there a better way to create a
string of text then the one used below.


Read_sql SELECT * FROM TBL_Picture WHERE FLD_FileName = "SailBoat.jpg"and
FLD_Path =" /var/www/html/slidecollection/WinterCarnival"
Result of read Resource id #2
Error Results 0
Number or Rows 0
Error Results Duplicate entry 
for key 1Result is of 2 is

//reading the database to see if record already exists
      $result = mysql_select_db ("Picture_DB", $link) or die ("Could not get the 
      $read_sql  = "SELECT * FROM TBL_Picture WHERE FLD_FileName = \"";
      $read_sql .= $fn_FileName;
      $read_sql .= "\"and FLD_Path =\" ";
      $read_sql .= $fn_Path;
      $read_sql .= "\"";
      echo " Read_sql ";
      echo $read_sql;
      $result = mysql_query($read_sql, $link) or die("could not read the table");
      echo "Result of read ";
      echo $result;
      echo " Error Results ";
      echo mysql_errno ($link);
      $number_of_rows = mysql_num_rows($result);
      echo " Number or Rows ";
      echo $number_of_rows;
//if return no rows then we need to add the record
      if  ($number_of_rows == 0){
        $insert_sql  = "INSERT INTO TBL_Picture  VALUES (\"";
        $insert_sql .= $fn_FileName;
        $insert_sql .= "\",\"";
        $insert_sql .= $fn_Path;
        $insert_sql .= "\",\"";
        $insert_sql .= $fn_Year;
        $insert_sql .= "\",\"";
        $insert_sql .= $fn_DescriptiveText;
        $insert_sql .= "\",\"";
        $insert_sql .= $fn_PictureName;
        $insert_sql .= "\")";
        echo " Insert Sql ";
        echo $insert_sql;
        $result2 = mysql_query($insert_sql, $link);
 //                 or die("could not write to the table ");
      echo " Error Results ";
      echo mysql_error ($link);
        echo "Result is of 2 is";
        echo $result2;

PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to