This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » PHP » Inser Record Posting to Dbase Table When No Fields Are Selected
Reply

Inser Record Posting to Dbase Table When No Fields Are Selected

Heather V
Freaking Member



Since: 30 May 2007
Posts: 61
Posted 09 Sep 2009 18:56:56

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?

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?
Patrick Julicher
Official Representative



Since: 04 Feb 2002
Posts: 1,208
Replied 15 Sep 2009 16:06:29
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
john henderson
Member



Since: 05 Feb 2009
Posts: 5
Replied 15 Sep 2009 18:44:59
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
Heather V
Freaking Member



Since: 30 May 2007
Posts: 61
Replied 16 Sep 2009 06:42:45
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

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency