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? |