【发布时间】:2016-03-24 22:54:57
【问题描述】:
我有一个可编辑的表单,允许我在单击特定字段时更改数据,但我无法将新数据保存在数据库中。(代码@fiddle)
html代码
<table>
<tr>
<td><span>text</span>
<input type='text' name='text' value='text' class='toedit' readonly='readonly' />
</td>
</tr>
</table>
脚本
$("table").on("focus", "input, select", function() {
$(this)
.prop("readonly", false)
.removeClass("toedit");
});
$("table").on("blur", "input, select", function() {
$(this)
.prop("readonly", true)
.addClass("toedit")
.siblings("span").text($(this).val());
});
$("table").on("click", "td", function() {
$(this).children().focus();
});
编辑查询是这样的,但不知道如何从脚本中获取值并将其添加到下面的查询中
$sql1="UPDATE `table_name` set name='".$text."' WHERE id='".$tableid."' ";
if(!mysqli_query($con,$sql1))
{
die('Error:' . mysqli_error($con));
}
table_name的表结构是这样的
id name
1 N1
2 N2
【问题讨论】:
-
您需要一种服务器端编程语言才能将某些内容保存到数据库中。
-
@caramba 更新了帖子,我有服务器端查询但不知道如何链接它们
-
也许你忘了添加
<form>包装所有输入字段。也不要忘记在表单标签中指定动作和方法
标签: javascript jquery html mysql ajax