我有一个表单,可以通过它输入值并将其保存在数据库中
表单代码为
<script>
$(document).ready(function () {
var sampleTags ;
$("#myTags").tagit({
availableTags: sampleTags,
afterTagAdded:function(){
$('[name="tags"]').val($("#myTags").tagit("assignedTags"));
//alert( $('[name="tags"]').val());
}
});
});
</script>
<form action="insert.php">
<input name="tags" id="myTags" >
<button class="submit" type="submit" value="submit" >Submit</button>
</form>
insert.php页面代码
$tag = $_POST['tags'];
echo $tag;
它给了我一个看起来像这样的o/p
first,second,third
我想从上面的 o/p 中删除逗号并将它们每个插入到表的单独行中。谁能告诉我如何分离上述o/p
最佳答案
您可以使用explode
并使用for循环
插入数据库
$tags = explode(",", $_POST['tags']);// convert in array break by comma
foreach($tags as $tag)
{
// your insert query
}
关于php - 从表单中获取值并保存在表的不同行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32865467/