所以我有这个网页,每当我点击一个按钮添加行时,它会为我添加一个额外的行。之后,将会出现一个完成按钮,用户点击它时会更新数据库。这是我的错误进入的地方。每当我更新时,他们都找不到我的$ _Post ['id']。这些是我的页面代码,您可以在每次单击按钮时添加行。点击一个按钮后更新数据库(它看起来很简单,但它不能工作请阅读)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="div"></div>
<button id='add' value="Add Row">Add Row</button>
<form action = newExpertise.php method="post">
<button id="finish" name = "finish" value ="Finish" onclick="clicktoindex()">Finish</button>
<input type='hidden' name='store' id='store'>
<script>
var x=1;
var count=0;
$('body').on('click','#add',function()
{
if(count <= 10)
{
$('#div').append("<form action = newExpertise.php method='post'><div class='line'><input type='text' name = 'txta"+x+"' id='txta"+ x +"'><span class =wordtab></span><input type='text' name = 'txtb"+x+"' id='txtb"+ x +"'><span class =wordtab></span><button class='delete' value ='Delete Row'>Delete Row</button></div><br></form>");
count++;
x++;
}
else
alert("Maximum 10 Skills");
});
$('body').on('click','.delete',function()
{
$(this).closest('.line').remove();
count--;
});
function clicktoindex(){
document.getElementById('store').value=count;
}
</script>
我认为这是因为当我完成按钮点击,它刷新页面,因此,我的文本框都将消失,所以他们不能够检测到文本框的ID($ _ POST [” txta1'])。我想用ajax来解决这个问题,但我希望我的页面在点击完成按钮后进入下一页。这些是我的代码,当我点击按钮完成。
if(isset($_POST['finish']))
{
for($x=1; $x <= $_POST['store']; $x++)
{
$finishquery = "INSERT INTO particulars_expertise (Particulars_ID, Expertise, Years_experience)
VALUES('".$_POST['storeid']."','".$_POST['txta1']."', '".$_POST['txtb1']."')";
if ($connect->query($finishquery) === TRUE)
{
}
else
{
echo "Error updating record: " . $connect->error;
}
}
}
已更新,但仍无法正常工作 – Samuel
您正在收到什么错误?还分享确切的文字得到这个'echo $ finishquery;' – C2486
他们说:“undefined索引:txta和txtb – Samuel