0 Replies Latest reply on Apr 23, 2010 1:31 PM by toad78

    INSERT into Multiple Tables: works fine except one field

    toad78 Level 1

      I have successfully been able to create a multiple INSERT query to post information to two tables, with the exception of one field in the 'images' table. When I attempt to INSERT (or upload in this case) a file, the filename does not record in the 'images' table 'image' field, but uploads just fine.

       

      If I remove '$new_bos_id" then 'image' will post, but not the 'bos_id' in the 'images' table, which I need to relate to the 'books_on_sale' table 'bos_id' field.

       

      Can someone tell me where I'm gonig wrong?

       

      $editFormAction = $_SERVER['PHP_SELF'];
      if (isset($_SERVER['QUERY_STRING'])) {
        $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
      }
      
      if (isset($editFormAction)) {
        if (isset($_SERVER['QUERY_STRING'])) {
            if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
              $editFormAction .= "&GP_upload=true";
              }
        } else {
          $editFormAction .= "?GP_upload=true";
        }
      }
      
      if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
        $insertSQL = sprintf("INSERT INTO books_on_sale (teaser, book, author) VALUES (%s, %s, %s)",
                             GetSQLValueString($_POST['teaser'], "text"),
                             GetSQLValueString($_POST['book'], "text"),
                             GetSQLValueString($_POST['author'], "text"));
      
        mysql_select_db($database_Tr_adconr25_jut, $Tr_adconr25_jut);
        $Result1 = mysql_query($insertSQL, $Tr_adconr25_jut) or die(mysql_error());
              
              $new_bos_id = mysql_insert_id();
      
              $insertSQL = sprintf("INSERT INTO images (bos_id, image) VALUES ($new_bos_id, %s)",
                             GetSQLValueString($_POST['bos_id'], "int"),
                             GetSQLValueString($_POST['image'], "text"));
                                                                                                  
              mysql_select_db($database_Tr_adconr25_jut, $Tr_adconr25_jut);
        $Result1 = mysql_query($insertSQL, $Tr_adconr25_jut) or die(mysql_error());
      
        $insertGoTo = "../list.php";
        if (isset($_SERVER['QUERY_STRING'])) {
          $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
          $insertGoTo .= $_SERVER['QUERY_STRING'];
        }
        header(sprintf("Location: %s", $insertGoTo));
      }
      ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
      
      
      <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,5000,'','','','','','');return document.MM_returnValue">
      <table width="80%" align="center" class="list">
      <tr valign="baseline">
      <td align="right" nowrap class="right">Upload Image:</td>
      <td><input name="image" type="file" id="image" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,5000,'','','','','','')" size="40" maxlength="40" /></td>
      </tr>
      <tr valign="baseline">
      <td align="right" valign="top" nowrap class="right">Teaser:</td>
      <td><textarea name="teaser" cols="50" rows="5"></textarea>
      </td>
      </tr>
      <tr valign="baseline">
      <td align="right" valign="top" nowrap class="right">Book Title:</td>
      <td><textarea name="book" cols="50" rows="5"></textarea>
      </td>
      </tr>
      <tr valign="baseline">
      <td align="right" nowrap class="right">Author:</td>
      <td><input type="text" name="author" value="" size="32"></td>
      </tr>
      <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td><input type="submit" class="btn" value="Insert"></td>
      </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
      <input type="hidden" />
      </form>