How would you write a sql statement that allows you to insert data obtained from a form but will be entered in either one tabe or another depending on what is selected on the form? I know how to insert the data from a form to a specified table but I need to be able to use the form to select which table the data will be entered into. Here is a copy of my form...
您如何编写一个sql语句,允许您插入从表单中获取的数据,但是将根据表单上选择的内容在一个tabe或另一个tabe中输入?我知道如何将表单中的数据插入到指定的表中,但我需要能够使用表单来选择将数据输入到哪个表中。这是我表格的副本......
print("<form action="<?=$PHP_SELF?>" enctype="multipart/form-data" method="post">
<fieldset>
<legend>Upload Your Motions and Orders Here</legend>
<table width="80%" border="0">
<tr>
<td class="label"> <label for="label">Select Your File:</label>
</p></td>
<td class="input"><input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="thefile" value="<? echo $thefile; ?>" accesskey="s" tabindex="10"></td>
</tr>
<tr>
<td class="label"><span class="input">
<label for="label">Type of File:</label>
</span></td>
<td class="input"><select name="field" id="field" value="<? echo $field; ?>" accesskey="t" tabindex="20">
<option value="Motions">Motions</option>
<option value="Orders">Orders</option>
</select> </td>
</tr>
<tr>
<td class="label"><label for="label">Name of File:</label> </td>
<td class="input"><label for="type"></label>
<input type="text" name="name" id="name" value="<? echo $name; ?>" accesskey="n" tabindex="30"></td>
</tr>
<tr>
<td class="label"><label for="label">Date Filed In Court:</label> </td>
<td class="input"><label for="date"></label>
<input type="text" name="date" id="date" value="<? echo $date; ?>" accesskey="f" tabindex="40"></td>
</tr>
<tr>
<td class="label"><span class="input">
<label for="label">Description:</label>
</span></td>
<td class="input"><textarea name="description" id="description" cols="30" rows="5" value="<? echo $description; ?>" accesskey="d" tabindex="50"></textarea></td>
</tr>
<tr>
<td class="label"> </td>
<td class="input"><input type="submit" name="submit" value="Upload This File" /></td>
</tr>
</table>
</fieldset>
</form>");`
<form action="<?=$PHP_SELF?>" enctype="multipart/form-data" method="post">
<fieldset>
<legend>Upload Your Motions and Orders Here</legend>
<table width="80%" border="0">
<tr>
<td class="label"> <label for="label">Select Your File:</label>
</p></td>
<td class="input"><input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="thefile" value="<? echo $thefile; ?>" accesskey="s" tabindex="10"></td>
</tr>
<tr>
<td class="label"><span class="input">
<label for="label">Type of File:</label>
</span></td>
<td class="input"><select name="field" id="field" value="<? echo $field; ?>" accesskey="t" tabindex="20">
<option value="Motions">Motions</option>
<option value="Orders">Orders</option>
</select> </td>
</tr>
<tr>
<td class="label"><label for="label">Name of File:</label> </td>
<td class="input"><label for="type"></label>
<input type="text" name="name" id="name" value="<? echo $name; ?>" accesskey="n" tabindex="30"></td>
</tr>
<tr>
<td class="label"><label for="label">Date Filed In Court:</label> </td>
<td class="input"><label for="date"></label>
<input type="text" name="date" id="date" value="<? echo $date; ?>" accesskey="f" tabindex="40"></td>
</tr>
<tr>
<td class="label"><span class="input">
<label for="label">Description:</label>
</span></td>
<td class="input"><textarea name="description" id="description" cols="30" rows="5" value="<? echo $description; ?>" accesskey="d" tabindex="50"></textarea></td>
</tr>
<tr>
<td class="label"> </td>
<td class="input"><input type="submit" name="submit" value="Upload This File" /></td>
</tr>
</table>
</fieldset>
</form>
The type of file selection field will be what determines the table the data will be inserted into.
文件选择字段的类型将决定数据将插入的表。
1 个解决方案
#1
I would stay away from running dynamic sql. Since you have a list of know types, you can put the logic to choose a table in a case statement at the app layer based on the file type. The other option is to create a stored procedure with a case statement, or a set of if statements. This way you don't construct dynamic sql for the insert.
我会远离运行动态SQL。由于您有已知类型的列表,因此可以根据文件类型将逻辑放在应用层的case语句中选择一个表。另一种选择是使用case语句或一组if语句创建存储过程。这样您就不会为插入构造动态sql。
#1
I would stay away from running dynamic sql. Since you have a list of know types, you can put the logic to choose a table in a case statement at the app layer based on the file type. The other option is to create a stored procedure with a case statement, or a set of if statements. This way you don't construct dynamic sql for the insert.
我会远离运行动态SQL。由于您有已知类型的列表,因此可以根据文件类型将逻辑放在应用层的case语句中选择一个表。另一种选择是使用case语句或一组if语句创建存储过程。这样您就不会为插入构造动态sql。