$result = mysqli_query($link, "INSERT INTO mytable...
`friends`,
`friend1`,
`friend2`,
`friend3`,
VALUES (NULL, '$friends',
'$friends[0]'
'$friends[1]'
'$friends[2]'
使用cloneya.js复制字段,我得到一组3个名字的数组值。发布到mysql,我在第一个字段(朋友)中得到三个名字,但在后续字段(friend1-3)中只有第一个名字的第一个,第二个和第三个字母。如何将每个名称插入单独的字段?
答案 0 :(得分:0)
$friends
is not an array in your case, its just a string. Which means that $friends[0]
will be the first character of that string, $friends[1]
will be the second character and so on. You must send the friends with a different variable name so you have $friends
which is a string and $otherName
as an array which you can use in your sql query.
Keep in mind to use prepared statements when you use sql queries which depends on variables. Also convert your tables to 3NF.