【发布时间】:2014-05-01 15:13:06
【问题描述】:
基本上我试图在数据库中输入两个数组,但我似乎无法真正将它们放入正确的表中。
这里是php函数的代码:
$numecap1 = $_POST['numecap'];
$contentcap1 = $_POST['contentcap'];
$numecap = implode(" ", $numecap1);
$contentcap = implode(" ", $contentcap1);
$count_name = count($_POST['numecap']);
for($i=0;$i<$count_name ;$i++){
$_numecap = mysqli_escape_string($con,$numecap[$i]);
$_contentcap = mysqli_escape_string($con, $contentcap[$i]);
$sql3 = "INSERT INTO `".$prefix."".$titlu."`(numecap, contentcap) VALUES ('$numecap', '$contentcap')";}
这是html表单(注意:java脚本添加了我需要多少文本标签):
<form action="" method="post">
Nume table <input type="text" name="table"><br>
Autor <input type="text" name="autor"><br>
Nrcap <input type="text" name="cap"><br>
<input type="button" onclick="addInput()"/>
<span id="responce"></span>
<script>
var boxName2 = 0;
var boxName = 0;
function addInput()
{
var boxName="numecap";
document.getElementById('responce').innerHTML+='<br/>Nume cap<input type="text" name="'+boxName+'[]" " /><br/>';
var boxName2="contentcap";
document.getElementById('responce').innerHTML+='<br/>Continut cap<input type="text" name="'+boxName2+'[]" " /><br/>';
}
</script>
<input type="submit" name="SubmitButton"/>
</form>
如果有人可以提供帮助,将不胜感激,因为我很绝望!
【问题讨论】:
-
那么你到底有什么问题呢?你有错误吗?您是否已将创建的查询转储并尝试直接针对数据库运行它?您实际上在哪里尝试查询数据库?
-
例如,如果数组 numecap 有 3 个元素,则将它们全部插入一个单元格中,我需要将它们放在不同的表格单元格中
-
$prefix和$titlu变量是什么? -
那么你需要查询
INSERT INTO table (column1, column2) VALUES ('value1a', 'value1b'), ('value2a', 'value2b'), ...的格式 -
$prefix $titlu 创建一个特定的数据库名称。
标签: php html arrays database insert