gpt4 book ai didi

php - 如何在php mysql中更新多个选择框的值

转载 作者:行者123 更新时间:2023-11-28 23:44:37 25 4
gpt4 key购买 nike

<select name="specialization" multiple>
<option value=""></option>
<option value="United States" selected>United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan" selected>Afghanistan</option>
<option value="Aland Islands">Aland Islands</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
</select>

如何更新数据库列中以逗号分隔的多个选择值。

最佳答案

<form method='POST' action='somepage.php'>
<select name="specialization[]" multiple>
<option value=""></option>
<option value="United States" selected>United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Afghanistan" selected>Afghanistan</option>
<option value="Aland Islands">Aland Islands</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
</select>
<input type='submit' value='submit'>
</form>

somepage.php

<?
$specialization = isset($_POST['specialization']) ? $_POST['specialization'] : [] ;
$totalSpec = sizeof($specialization);
for($i = 0; $i < $totalSpec; $i++){
$spec = $specialization[$i];
$query="INSERT INTO TableName SET SpecializationColumnName='$spec'";
}?>

<?
$specialization = isset($_POST['specialization']) ? implode(",",$_POST['specialization']) : '';
$query = "";
if(!empty($specialization)){
$query = "INSERT INTO TableName SET SpecializationColumnName='$specialization'";
}?>

关于php - 如何在php mysql中更新多个选择框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33776088/

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