gpt4 book ai didi

sql - 如何更改SQL插入语句的目标表?

转载 作者:行者123 更新时间:2023-11-29 03:15:19 25 4
gpt4 key购买 nike

您将如何编写一个 sql 语句,允许您插入从表单中获取的数据,但将根据在表单上选择的内容输入到一个或另一个表中?我知道如何将表单中的数据插入到指定的表中,但我需要能够使用表单来选择将数据输入到哪个表中。这是我的表格的副本...

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">&nbsp;</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">&nbsp;</td>
<td class="input"><input type="submit" name="submit" value="Upload This File" /></td>
</tr>
</table>
</fieldset>
</form>

文件选择字段的类型将决定数据将插入到的表。

最佳答案

我会远离运行动态 sql。由于您有一个已知类型列表,因此您可以根据文件类型在应用程序层的 case 语句中放置选择表的逻辑。另一种选择是使用 case 语句或一组 if 语句创建存储过程。这样您就不会为插入构建动态 sql。

关于sql - 如何更改SQL插入语句的目标表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/383054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com