使用 JavaScript 更新 SQL 记录
update sql record using javascript
我之前有一个简单的形式:
<form method="post" action="firstbillsubmitbal.php?id=#COL1#">
<input name="currentbal" type="text" id="currentbal" class="input-mini" />
<input type="submit" id="submit" value="Save" class="btn btn-success" />
</form>
哪个调用此页面来处理第一账单提交.php
$dealID = $_GET["id"];
$currentbal = mysql_real_escape_string(stripslashes($_POST['currentbal']));
$sql = mysql_query("UPDATE deals SET
currentbal = '$currentbal',
currentbalDone = 'Yes'
WHERE deals.dealID = '$dealID'") or die (mysql_error());
它对于单个事务工作正常。但是我需要对其进行一些编辑,因为我现在正在表中显示我的数据。当我每行单击表格上的 btn 时,我现在有了这个 js 代码,传递我的 row_id 和当前 calue,我让它工作了,但我想知道从这个 js 代码中我如何处理我的表单?
function funcEdit(row_id){
var currentbal = document.getElementById('currentbal' + row_id).value;
var r=confirm("Are You Sure You Want To Proceed?");
if(r==true) {
alert("Record is saved");
} else {
alert("Cancelling Transaction");
}
}
js 代码目前只有两个变量,即
row_id
= 这基本上是数据库行的 ID,并且 currentbal
= 哪个是我要上传到数据库的值
的问题基本上是我如何调用我的firstbillsubmitbal.php
文件以及我在我的 php 文件上编辑什么/如何,以便我的row_id和currentbal
上传到我的数据库,因为我不再使用 POST。
感谢您的回复。所以我浏览了一些SO答案和一些教程,这就是我的js代码发生的事情。
function funcEdit(row_id){
var currentbal = document.getElementById('currentbal' + row_id).value;
var dealID = row_id;
//organize the data properly
var data = 'currentbal=' + currentbal.val() + '&dealID=' + dealID.val();
//start the ajax
$.ajax({
url: "firstbillsubmitbal.php",
type: "GET",
data: data,
cache: false,
success: function() {
$('#message').html("<h2>Current balance has been updated!</h2>")
}
});
}
这就是我的第一个账单提交.php页面发生的事情
$dealID = $_GET['dealID']
$currentbal = $_GET['currentbal']
$sql = mysql_query("UPDATE deals SET
currentbal = '$currentbal',
currentbalDone = 'Yes'
WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());
但是当我单击按钮调用我的函数时没有任何反应。我错过了什么?
另外,这是我调用函数的方式。 #COL1# 是我的行 ID 值。
<a href="javascript: funcEdit(#COL1#);" class="btn btn-success">Update</a>
你的函数是否被正确调用row_id数据?
如果是这样,那么这可能会给你一个技巧,
function funcEdit(row_id){
var currentbal = document.getElementById('currentbal' + row_id).value;
var dealID = row_id;
//start the ajax
$.ajax({
url: "firstbillsubmitbal.php",
type: "GET",
//pass data like this
data: {currentbal:currentbal.val(),dealID: dealID.val()},
cache: false,
success: function(data) {
if (data=="1")
$('#message').html("<h2>Current balance has been updated!</h2>")
}
});
}
并在 PHP 文件中
$dealID = $_GET['dealID']
$currentbal = $_GET['currentbal']
$sql = mysql_query("UPDATE deals SET
currentbal = '$currentbal',
currentbalDone = 'Yes'
WHERE deals.dealID = '$dealID' LIMIT 1") or die (mysql_error());
echo "1" ; // if update successful
else echo "0" // if update unsuccessful
HTML :
<form method="post" action="firstbillsubmitbal.php">
<input name="currentbal" type="text" id="currentbal" class="input-mini" />
<a href="#" onclick="funcEdit(#COL1#); return false;" class="btn btn-success">Update</a>
</form>
.JS:
function funcEdit(row_id){
var currentbal = $("#currentbal").val();
//organize the data properly
var data = 'currentbal=' + currentbal + '&dealID=' + row_id;
//start the ajax
$.ajax({
url: "firstbillsubmitbal.php",
type: "GET",
data: data,
cache: false,
success: function() {
$('#message').html("<h2>Current balance has been updated!</h2>")
}
});
}
希望它对你有用!
相关文章:
- 使用Dnamics CRM 2011中的JavaScript读取子网格的所有记录,而不考虑活动页面
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- AngularJs对所有页面中的所有记录进行排序
- 有没有一种方法可以在控制台关闭的情况下让console.log()在IE中记录消息
- window.location替换并传递URL历史记录条目中的变量
- Javascript历史记录转换为php行
- JavaScript,PHP-用JavaScript将多个数据库记录发送到变量或表
- 猫鼬在特定记录中查找嵌套记录
- 浏览器何时记录历史记录
- 捕获初始RedQueryBuilder查询中的SQL问题
- 将一个表的id与另一个表中的user_id进行匹配,以获取mysql中的记录
- Breeze 查询不提取检查 sql 服务器表中日期列的记录
- 如何根据下拉选择框中的选择更新sql数据库中的特定记录
- 在插入第二个记录时,Web SQL数据库版本错误
- 将SQL查询返回的记录拆分为一个数组
- 在Sql Server 2008中插入记录的问题
- PHP SQL记录表无法通过变量连接
- Javascript -显示多个sql记录
- 使用 JavaScript 更新 SQL 记录
- 如何从日期中删除时间从JavaScript拉记录从SQL