您如何编写一个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>
文件选择字段的类型将决定数据将插入的表格。
答案 0 :(得分:1)
我会远离运行动态sql。由于您有已知类型的列表,因此可以根据文件类型将逻辑放在应用层的case语句中选择一个表。另一种选择是使用case语句或一组if语句创建存储过程。这样就不会为插入构造动态sql。