Forums

PHP

This topic is locked

INSERT Record to Multiple Tables - Filename Not Uploading

Posted 23 Apr 2010 22:19:46
1
has voted
23 Apr 2010 22:19:46 Heather V posted:
Scenario:
I have a form with the PHP Upload extension (which works just fine, so I won't post this in that forum) and the information is to post into two tables:

IMAGES:
image_id (PK)
bos_id (FK)
image

The 'images' table is to have the filename that is associated with the Primary Key 'bos_id' in the 'books_on_sale' table.

BOOKS_ON_SALE:
bos_id
teaser
title
author

Code:
$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));
}



<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">&nbsp;</td>
<td><input type="submit" class="btn" value="Insert"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
<input name="image" type="hidden" id="image" />
</form>


The problem is that everything posts as it should with the exception of the filename in the 'image' field of the 'images' table.

Any help would be appreciated!

Reply to this topic