[英]Update MySQL using AJAX and PHP
I'll go slow, not for your sake..for mine. 我会慢慢走,不是为了你。是我的。 I'm real new at trying to to do this.
我真的很想这样做。 What I'm trying to do is update live a MySQL DB from an HTML table.
我正在尝试从HTML表实时更新MySQL数据库。 This is how each is built.
这就是每个构建的方式。
echo ("<td id=\"callsign:$row[recordID]\" contenteditable=\"true\"
onClick=\"showEdit(this)\"
onBlur=\"saveToDatabase(this,'callsign',$row[recordID])\"
style='text-transform:uppercase'>
$row[callsign]</td>");
This is how it renders. 这就是它的渲染方式。
<td id="callsign:6" contenteditable="true" onclick="showEdit(this)" onblur="saveToDatabase(this,'callsign',6)" style="text-transform: uppercase; background-color: rgb(253, 253, 253); background-position: initial initial; background-repeat: initial initial;">
KA0SXY</td>
Here is the function that gets called. 这是被调用的函数。
function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#FFF url(loaderIcon.gif) no-repeat right");
$.ajax({
url: "saveedit.php",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
$(editableObj).css("background","#FDFDFD");
}
});
}
And here is the PHP. 这是PHP。
<?php
require_once "dbConnectDtls.php";
$result = mysql_query("UPDATE NetLog set " . $_POST["column"] . " = '".$_POST["editval"]."' WHERE recordID=".$_POST["id"]);
echo $result;
?>
When I tab from this cell to the next the only thing that gets executed is the .gif. 当我从此单元格跳至下一个时,唯一会执行的是.gif。 The MySQL does not get updated, what am I doing wrong?
MySQL无法更新,我在做什么错?
Thanks in advance for not treating me like a dummy, but helping me learn. 在此先感谢您不把我当做虚拟人,而是帮助我学习。
Followup to suggestions: 后续建议:
I'm afraid I'm making no headway on this. 恐怕我在这方面没有进展。 Is anyone willing to actually write a working example that I can follow?
是否有人愿意写一个我可以效仿的可行示例?
For a newcomer there are many things you should take care in your script: 对于新手来说,您应该在脚本中注意许多事项:
Also you are not printing the "data" variable that gets returned to see if is the expected result in server. 另外,您不打印返回的“数据”变量,以查看服务器中的预期结果。 You could do it with:
您可以这样做:
console.log(data); 的console.log(数据);
Other than that everything looks good in your script ;) 除此之外,脚本中的所有内容看起来都不错;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.