Forums

PHP

This topic is locked

Inser Record Posting to Dbase Table When No Fields Are Selected

Posted 09 Sep 2009 18:56:56
1
has voted
09 Sep 2009 18:56:56 Heather V posted:
I've set up my form to upload multiple files and insert multiple records to a dbase table as such:

<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,3000,'','','','','','');return document.MM_returnValue">
<table width="700" align="center" id="registration">
<tr valign="baseline">
<td nowrap align="right"><strong>Upload File:</strong></td>
<td valign="top"><input name="filename1" type="file" id="filename1" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,3000,'','','','','','')" size="50" /></td>
<td valign="top"><select name="category1" id="category1">
<?php
do {  
?>
<option value="<?php echo $row_getCat['gc_id']?>"><?php echo $row_getCat['category']?></option>
<?php
} while ($row_getCat = mysql_fetch_assoc($getCat));
  $rows = mysql_num_rows($getCat);
  if($rows > 0) {
      mysql_data_seek($getCat, 0);
	  $row_getCat = mysql_fetch_assoc($getCat);
  }
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><strong>Upload File:</strong></td>
<td valign="top"><input name="filename2" type="file" id="filename2" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,3000,'','','','','','')" size="50" /></td>
<td valign="top"><select name="category2" id="category2">
<?php
do {  
?>
<option value="<?php echo $row_getCat['gc_id']?>"><?php echo $row_getCat['category']?></option>
<?php
} while ($row_getCat = mysql_fetch_assoc($getCat));
  $rows = mysql_num_rows($getCat);
  if($rows > 0) {
      mysql_data_seek($getCat, 0);
	  $row_getCat = mysql_fetch_assoc($getCat);
  }
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><strong>Upload File:</strong></td>
<td valign="top"><input name="filename3" type="file" id="filename3" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,3000,'','','','','','')" size="50" /></td>
<td valign="top"><select name="category3" id="category3">
<?php
do {  
?>
<option value="<?php echo $row_getCat['gc_id']?>"><?php echo $row_getCat['category']?></option>
<?php
} while ($row_getCat = mysql_fetch_assoc($getCat));
  $rows = mysql_num_rows($getCat);
  if($rows > 0) {
      mysql_data_seek($getCat, 0);
	  $row_getCat = mysql_fetch_assoc($getCat);
  }
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><strong>Upload File:</strong></td>
<td valign="top"><input name="filename4" type="file" id="filename4" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,3000,'','','','','','')" size="50" /></td>
<td valign="top"><select name="category4" id="category4">
<?php
do {  
?>
<option value="<?php echo $row_getCat['gc_id']?>"><?php echo $row_getCat['category']?></option>
<?php
} while ($row_getCat = mysql_fetch_assoc($getCat));
  $rows = mysql_num_rows($getCat);
  if($rows > 0) {
      mysql_data_seek($getCat, 0);
	  $row_getCat = mysql_fetch_assoc($getCat);
  }
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><strong>Upload File:</strong></td>
<td valign="top"><input name="filename5" type="file" id="filename5" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG,gif,jpg,jpeg,bmp,png',false,3000,'','','','','','')" size="50" /></td>
<td valign="top"><select name="category5" id="category5">
<?php
do {  
?>
<option value="<?php echo $row_getCat['gc_id']?>"><?php echo $row_getCat['category']?></option>
<?php
} while ($row_getCat = mysql_fetch_assoc($getCat));
  $rows = mysql_num_rows($getCat);
  if($rows > 0) {
      mysql_data_seek($getCat, 0);
	  $row_getCat = mysql_fetch_assoc($getCat);
  }
?>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td colspan="2" valign="top"><input type="submit" value="Insert record"></td>
</tr>
</table>

<input type="hidden" name="MM_insert" value="form1">
</form>


I have created multiple Insert Record Behaviors to post to the dbase table after some clicks on the Insert button. Problem is, what if someone only wants to use 2 out of 5 fields on this form? Well, the rest of the three fields post as Null, which I don't want. I don't want them to post at all! Does this require an IF/ELSE statement around the Insert Record Server Behavior?

Currently I have this:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO gallery (gc_id, filename) VALUES (%s, %s)",
                       GetSQLValueString($_POST['category2'], "int"),
                       GetSQLValueString($_POST['filename2'], "text"));

  mysql_select_db($database_radmin, $radmin);
  $Result1 = mysql_query($insertSQL, $radmin) or die(mysql_error());

  $insertGoTo = "list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}


I'd like to know how this can be modified for the logical function: "If there is something to upload, then post, otherwise, don't post anything".

Can someone advise?

Replies

Replied 15 Sep 2009 16:06:29
15 Sep 2009 16:06:29 Patrick Julicher replied:
Hi Heather,

Ther might be ways to get this working, although I cannot think of any right now! Maybe you would be better off using the ADvanced Multi Uploader by DMXzone: www.dmxzone.com/go?15505??
This would do exactly what you want! Keep in mind that this extension still has issues when being used on a page with a restrict access behavior applied. Read the forum for this extension for more info.

Kind regards, Patrick
Replied 15 Sep 2009 18:44:59
15 Sep 2009 18:44:59 john henderson replied:
Hi Heather,

I can see what your doing, you simply need to have a validating loop. When a record is posted ensure that at least 1 field is mandatory for all records. If this field is empty/blank, then simply drop the record and continue to the next.

Sorry, Its not code, but the logic does work

john
Replied 16 Sep 2009 06:42:45
16 Sep 2009 06:42:45 Heather V replied:
QuoteHi Heather,

I can see what your doing, you simply need to have a validating loop. When a record is posted ensure that at least 1 field is mandatory for all records. If this field is empty/blank, then simply drop the record and continue to the next.

Sorry, Its not code, but the logic does work

john


I agree that the logic would work; unfortunately, I wasn't able to get help the time I needed it and I wound up purchasing the multiple uploader. It works nice, but I hope when the DMXZone programmers are able to add extra features (i.e., multiple text box insertions, menu selections, etc.) we won't be charged extra when the upgrade comes out. I think that these extra features would be valuable to multiple uploads (at least in my case).

Right now, I have to forward the user to go to another page to edit each file that has been uploaded in order to update any information regarding the files. It's not too much of a hassle, just extra time.

I guess we'll see!

Reply to this topic