gpt4 book ai didi

javascript - 更新不起作用

转载 作者:行者123 更新时间:2023-11-29 11:32:35 25 4
gpt4 key购买 nike

这是我的索引页,数据获取正常,但更新表不起作用,你能帮我解决这个问题吗?

索引页

<script>
jQuery("#rowed2").jqGrid({
url:'server.php',
datatype: "json",
colModel:[
{name:'WeekNo',index:'WeekNo', width:30 , editable:false,editrules : { required: false}},
{name:'WeekBeginning',index:'WeekBeginning', width:100 ,editable:true,editrules : { required: true}},
{name:'SITE',index:'SITE', width:40 , editable:true,editrules : { required: true}},
{name:'Name',index:'Name', width:150,align:"center" , editable:true,editrules : { required: true}},
{name:'WFH',index:'WFH', width:40, classes: 'cvteste', editable:true,editrules : { required: true}},
{name:'Login',index:'Login', width:80, editable:true,editrules : { required: false}},
{name:'Manager_Login',index:'Manager_Login', width:90 , editable:true,editrules : { required: true}},
{name:'Lead',index:'Lead', width:70, editable:true,editrules : { required: true}},
{name:'Cost_center',index:'Cost_center', width:70, editable:true,editrules : { required: true}},
{name:'Business_Title',index:'Business_Title', width:100, editable:true,editrules : { required: true}},
{name:'Function',index:'Function', width:70, editable:true,editrules : { required: true}},
{name:'Workgroup',index:'Workgroup', width:70, editable:true,editrules : { required: true}},
{name:'Login_time',index:'Login_time', width:70, editable:true,editrules : { required: true}},
{name:'ROLE',index:'ROLE', width:70,editable:true,editrules : { required: true}},
{name:'Secondary_Skill',index:'Secondary_Skill', width:90, editable:true,editrules : { required: true}},
{name:'Weekoff',index:'Weekoff', width:60, editable:true,editrules : { required: true}}
],

rowNum:100,
rowList:[100,200,300],
pager: '#prowed2',
//sortname: ('WeekNo','Name') ,
viewrecords: true,
height:'500px',
sortorder: "asc",
gridComplete: function(){
var ids = jQuery("#rowed2").jqGrid('getDataIDs');
for(var i=0;i<ids.length;i++){
var cl = ids[i];
be = "<input style='height:22px;width:40px;' type='button' value='Edit' onclick=\"jQuery('#rowed2').jqGrid('editRow','"+cl+"');\" />";
se = "<input style='height:22px;width:40px;' type='button' value='Save' onclick=\"jQuery('#rowed2').jqGrid('saveRow','"+cl+"');\" />";
ce = "<input style='height:22px;width:50px;' type='button' value='Cancel' onclick=\"jQuery('#rowed2').jqGrid('restoreRow','"+cl+"');\" />";
jQuery("#rowed2").jqGrid('setRowData',ids[i],{act:be+se+ce});
}
},
editurl: "update.php"
});
jQuery("#rowed2").jqGrid('navGrid',"#prowed2{edit:true,add:true,del:true});

var timeoutHnd;
var flAuto = true;
function doSearch(ev){
if(!flAuto)return;
if(timeoutHnd) clearTimeout(timeoutHnd);
timeoutHnd = setTimeout(gridReload,500);
}
function gridReload(){
var nm_mask = jQuery("#login").val();
var cd_mask = jQuery("#man").val();
var func = jQuery("#func").val();
jQuery("#rowed2").jqGrid('setGridParam',{url:"server.php? nm_mask="+nm_mask+"&cd_mask="+cd_mask+"&func="+func,page:1}).trigger("reloadGrid");

}
</script>

这里,如果我在 WHERE 条件下使用 WeekNo,它会显示错误 undefined variable ,因此我不使用 WeekNo,那么它不会更新数据库,甚至不会生成日志文件。

更新页面

    <?php


$con = mysqli_connect("localhost", "user", "password", "DB");


//This contains the data that will update the db
//$WeekNo = $_POST['WeekNo'];
$WeekBeginning = $_POST['WeekBeginning'];
$SITE = $_POST['SITE'];
$Name = $_POST['Name'];
$WFH = $_POST['WFH'];
//$Login = $_POST['Login'];
$Manager_Login = $_POST['Manager_Login'];
$Lead = $_POST['Lead'];
$Cost_center = $_POST['Cost_center'];
$Business_Title = $_POST['Business_Title'];
$Function = $_POST['Function'];
$Workgroup = $_POST['Workgroup'];
$Login_time = $_POST['Login_time'];
$ROLE = $_POST['ROLE'];
$Secondary_Skill = $_POST['Secondary_Skill'];
$Weekoff = $_POST['Weekoff'];

$sql = "UPDATE EmpMasterTB SET WeekBeginning='$WeekBeginning', SITE='$SITE', Name ='$Name', WFH='$WFH', Manager_Login='$Manager_Login', Lead='$Lead', Cost_center='$Cost_center', Business_Title='$Business_Title', Function='$Function', Workgroup='$Workgroup', Login_time='$Login_time', ROLE='$ROLE', Secondary_Skill='$Secondary_Skill', Weekoff='$Weekoff' WHERE ROLE = $_POST[ROLE] AND Login = $_POST[Login]";

mysqli_query($con,$sql) or die(mysqli_error($con));
mysqli_close($con);
?>

最佳答案

UPDATE 查询的 WHERE 条件应为:

WHERE ROLE = '$_POST[ROLE]' AND login = '$_POST[Login]'

绑定(bind)变量(尤其是字符串类型)时,您应该使用记号 (') 将它们合并到查询中。

此外,请使用 *_real_escape_string()在将它们绑定(bind)到您的查询之前。

$role = mysqli_real_escape_string($con, $_POST["ROLE"]);

POST 提交的数据执行其余操作。

关于javascript - 更新不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37156416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com