Javascript 点击按钮后更新数据库(可能看起来很简单,但无法工作,请继续阅读)
因此,我有这个页面,每当我点击一个按钮添加行,它会为我添加一个额外的行。之后,将有一个finish按钮,当用户单击它时,它将更新数据库。这就是我的错误所在。每当我更新时,他们都找不到我的$_帖子['id']。这些是我的页面代码,您可以在每次单击按钮时添加行Javascript 点击按钮后更新数据库(可能看起来很简单,但无法工作,请继续阅读),javascript,php,html,ajax,Javascript,Php,Html,Ajax,因此,我有这个页面,每当我点击一个按钮添加行,它会为我添加一个额外的行。之后,将有一个finish按钮,当用户单击它时,它将更新数据库。这就是我的错误所在。每当我更新时,他们都找不到我的$_帖子['id']。这些是我的页面代码,您可以在每次单击按钮时添加行 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="div
<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>
添加行
完成
var x=1;
var计数=0;
$('body')。在('click','add',function()上
{
如果(计数错误);
}
}
}
像这样更改查询,您忘记添加)
试试下面的代码,上面的代码中有很多错误
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action ="newExpertise.php" method="post">
<div id="skills">
<div class="skill">
<input type="text" name="skills[]" />
<button type="button" class="delete">Delete</button>
</div>
</div>
<button id="add" value="Add Row">Add Row</button>
<button type="submit" id="finish" name ="finish" value="Finish">Finish</button>
<input type='hidden' name='store' id='store'>
</form>
<script>
var x=1;
var count=0;
$('body').on('click','#add',function()
{
if(count <= 10)
{
$('#skills').append('<div class="skill"><input type="text name="skills[]" /><button type="button" class="delete">Delete</button></div>');
count++;
x++;
}
else
alert("Maximum 10 Skills");
});
$('body').on('click','.delete',function()
{
$(this).closest('.skill').remove();
count--;
});
function clicktoindex(){
document.getElementById('store').value=count;
}
删除
添加行
完成
var x=1;
var计数=0;
$('body')。在('click','add',function()上
{
如果(数一数你得到了什么错误?也要分享通过这个echo$finishquery;
得到的确切文本"未定义索引:txta和txtb这里是txta
和txtb
,您使用的是txta1
而不是txta
。哦,是的,我很抱歉输入错误,我指的是txta1和txtb1。我硬编码了txta1和txtb1,因为我只想尝试一下是否可以更新1组数据,但徒劳无功。我想每次单击添加2个文本框,当前是“添加”按钮不起作用
$finishquery = "INSERT INTO `particulars_expertise`(`Particulars_ID`, `Expertise`, `Years_experience`)
VALUES('$_POST[storeid]','$_POST[txta1]', '$_POST[txtb1]')";
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action ="newExpertise.php" method="post">
<div id="skills">
<div class="skill">
<input type="text" name="skills[]" />
<button type="button" class="delete">Delete</button>
</div>
</div>
<button id="add" value="Add Row">Add Row</button>
<button type="submit" id="finish" name ="finish" value="Finish">Finish</button>
<input type='hidden' name='store' id='store'>
</form>
<script>
var x=1;
var count=0;
$('body').on('click','#add',function()
{
if(count <= 10)
{
$('#skills').append('<div class="skill"><input type="text name="skills[]" /><button type="button" class="delete">Delete</button></div>');
count++;
x++;
}
else
alert("Maximum 10 Skills");
});
$('body').on('click','.delete',function()
{
$(this).closest('.skill').remove();
count--;
});
function clicktoindex(){
document.getElementById('store').value=count;
}