gpt4 book ai didi

php - 删除sql表数据然后插入多个可变数量的行

转载 作者:行者123 更新时间:2023-11-30 22:49:21 24 4
gpt4 key购买 nike

有人可以帮忙吗?尝试为一个乐队创建一个日历条目页面,他们可以在自己的网站上自行更新。

html入口页面:

<form action="addgigtimes.php" method="POST">
<fieldset class='multi'>
<legend><h5>Gig 1</h5></legend>

<label for='weekday' class='accessAid'></label>
<select id='weekday' name='weekday'>
<option value='' selected>Day of week</option>
<option value='Monday'>Monday</option>
<option value='Tuesday'>Tuesday</option>
<option value='Wednesday'>Wednesday</option>
<option value='Thursday'>Thursday</option>
<option value='Friday'>Friday</option>
<option value='Saturday'>Saturday</option>
<option value='Sunday'>Sunday</option></select>



<label for='day' class='accessAid'></label>
<select id='day' name='day'><option value='' selected>--Day--</option>
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option></select>

<label for='month' class='accessAid'></label>
<select id='month' name='month'><option value='' selected>--Month--</option>
<option value='01'>01 (Jan)</option>
<option value='02'>02 (Feb)</option>
<option value='03'>03 (Mar)</option>
<option value='04'>04 (Apr)</option>
<option value='05'>05 (May)</option>
<option value='06'>06 (Jun)</option>
<option value='07'>07 (Jul)</option>
<option value='08'>08 (Aug)</option>
<option value='09'>09 (Sep)</option>
<option value='10'>10 (Oct)</option>
<option value='11'>11 (Nov)</option>
<option value='12'>12 (Dec)</option></select>

<label for='year' class='accessAid'></label><select id='year' name='year'>
<option value='' selected>--Year--</option>
<option value='2015'>2015</option>
<option value='2016'>2016</option>
</select>
venue
<input type="text" class="input" name="venue" />
location
<input type="text" class="input" name="location" />
time
<input type="text" class="input" name="time" />
</fieldset>

<button type="reset" style="border: 0; background: transparent">
<img src="images/reset.jpg" alt="reset" style="margin-right:19px "/>
</button>
<button type="submit" value="submit" style="border: 0; background:transparent">
<img src="images/submit.jpg" alt="submit" />
</button>
</form>

我将重复 fieldset 代码 30 次,这样乐队一次最多可以输入 30 场演出。

这是PHP代码:

$sql = "DELETE FROM gigtimes";

$weekday = $_POST['weekday'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$venue = $_POST['venue'];
$location = $_POST['location'];
$time = $_POST['time'];


$rt=mysql_query("insert into guestbook(weekday,day,month,year,venue,location,time) VALUES ('$weekday','$day','$month','$year','$venue','$location','$time')");
echo mysql_error();

所以基本上删除数据库中已有的内容然后更新。我只是不确定如何处理行 ID?谁能解释一下。谢谢,贝琪

最佳答案

我有一个类似乐队的网站正在制作中,所以我知道你的痛苦。我做的一件事是也插入乐队名称,这样如果乐队想要删除某些内容,它会搜索他们的名称并删除字段,例如:

$sql = "DELETE FROM gigtimes WHERE band_name = '$band_name'";

这并不完美,因为理论上可能有多个同名乐队,因此要防止这种情况发生,请使乐队名称唯一。这非常适合我。如果您需要更多信息,请告诉我。

关于php - 删除sql表数据然后插入多个可变数量的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28596449/

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