[英]Insert multiple inputs with same name, into one array [row] (separated by "^")
I have multiple inputs (never being the same, because it's a dynamic add/remove jquery script, and it is all dependent on how many "tracks" the user wants to enter).我有多个输入(永远不会相同,因为它是一个动态添加/删除 jquery 脚本,它完全取决于用户想要输入多少“曲目”)。 I WILL NEVER KNOW HOW MANY WILL BE THERE.我永远不知道那里会有多少人。 Below is an example of if a user chooses to add four "tracks" to their "mixtape".下面是一个示例,说明用户是否选择将四个“曲目”添加到他们的“混音带”。
<input size="32" class="mixtapetrack" type="textbox" id="track[1]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[2]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[3]" name="track[]" >
<input size="32" class="mixtapetrack" type="textbox" id="track[4]" name="track[]" >
When the form is submited (PHP POSTED), I want to take all of the inputs and combine them into one array, but sepparating them all by "^^^" .提交表单时(PHP POSTED),我想获取所有输入并将它们组合成一个数组,但将它们全部分开"^^^" 。
This is what I have so far, for rendering out the inputs (NOT WORKING).这是我目前所拥有的,用于渲染输入(不工作)。
$trackVAR = $_POST['track'];
$allmixtapetracks = "";
foreach ($trackVAR as $value) {
$allmixtapetracks .= '' . $value . '^';
}
And This is what i'm using to insert into my table (WORKS, tested it without the variable and entered absoloute data)这就是我用来插入到我的表中的内容(WORKS,在没有变量的情况下对其进行了测试并输入了绝对数据)
$sql = mysql_query("INSERT INTO mixtapes (title, songs, posted_by_id, description, date)
VALUES('$mixtapetitle','$allmixtapetracks','$posted_by_id','$mixtapedescription', now())")
or die (mysql_error());
In the end I want it to look like this inside of the songs row最后我希望它在歌曲行中看起来像这样
Title of first song haha ^^^ Title of second song!!!第一首歌的歌名哈哈^^^第二歌的歌名!!! ^^^ The Title Of the third! ^^^第三个标题! ^^^ And The Title OF the Fourth ^^^和第四个的标题
Replace your following code:替换您的以下代码:
$trackVAR = $_POST['track'];
$allmixtapetracks = "";
foreach ($trackVAR as $value) {
$allmixtapetracks .= '' . $value . '^';
}
with this:有了这个:
$allmixtapetracks=implode('^^^',$_POST['track']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.