gpt4 book ai didi

php - 在ajax x-editable之后用条件更新php中的sql表

转载 作者:行者123 更新时间:2023-11-29 14:02:26 26 4
gpt4 key购买 nike

我需要你的帮助。

我编写了一个代码,使用 ajax jquery 在表中动态创建新行。

var nouvelle_ligne = $('<tr><td class="thtime">'+hours+'h'+minutes+'</td><td>Modification de l\'équipe de Quart : <b class="textepersocdq">'+chefdequart+'</b> prend la fonction de Chef de Quart et <b class="textepersoadj">'+adjoint+'</b> prend celle d\'adjoint.</td><td class="button"><button class="editperso"><i class="icon-pencil"></i></button></td><td class="button"><button class="trashperso"><i class="icon-trash"></i></button></td></tr>').fadeIn('fast');
$('#tablemc').append(nouvelle_ligne);

在这个新行中,我有一个按钮可以使用 x-editable 库进行编辑。

$(document).on("click", ".editperso", function(g){
g.stopPropagation();
var $CellParent = $(this).closest('td').prev().children('b');
editperso2($CellParent); });

function editperso2(bCellToEdit) {
bCellToEdit.editable({
mode: 'inline',
inputclass: 'input-medium texteperso',
type: 'text',
success: function() {
var cmsperso = $('.textepersocms').next('span').children('div').children('form').children('div').children('div').children('div').children('input.texteperso').val();
var chefdequart = $('.textepersocdq').next('span').children('div').children('form').children('div').children('div').children('div').children('input.texteperso').val();
var adjoint = $('.textepersoadj').next('span').children('div').children('form').children('div').children('div').children('div').children('input.texteperso').val();
var cmsperso2 = $(this).closest('td').children('.textepersocms').html();
var chefdequart2 = $(this).closest('td').children('.textepersocdq').html();
var adjoint2 = $(this).closest('td').children('.textepersoadj').html();

console.log(cmsperso);
console.log(chefdequart);
console.log(adjoint);
console.log(cmsperso2);
console.log(chefdequart2);
console.log(adjoint2);

$.ajax({
type: "POST",
url: "form/update/updateperso.php",
async: false,
data: { cmsperso: cmsperso, cmsperso2: cmsperso2, chefdequart: chefdequart, chefdequart2: chefdequart2, adjoint: adjoint, adjoint2: adjoint2 }
});
}
});}

此代码将 转换为输入变量(adjoint、chefdequart 和 cmsperso 是新值,adjoint2、chefdequart2 和 cmsperso2 是更改前的值)。

最后我有一个 php 文件可以更新 mysql 表,但它不起作用。

elseif (empty($_POST['cmsperso']) && !empty($_POST['chefdequart']) && !empty($_POST['adjoint'])) {

if (isset($_POST['chefdequart']) && isset($_POST['chefdequart2']) && isset($_POST['adjoint']) && isset($_POST['adjoint2'])) {

$chefdequart = $_POST['chefdequart'];
$chefdequart2 = $_POST['chefdequart2'];
$adjoint = $_POST['adjoint'];
$adjoint2 = $_POST['adjoint2'];

$pos1 = strcasecmp($adjoint, $adjoint2);
$pos2 = strcasecmp($chefdequart, $chefdequart2);

if ($pos1===0 && $pos2!==0) {

$updateperso4 = "UPDATE `Operations` SET `chefdequart`=\"$chefdequart\" WHERE `cmsperso`='' AND `chefdequart`=\"$chefdequart2\" AND `adjoint`=\"$adjoint2\"";

if($updateperso4) {
echo json_encode(array("status"=>"ok"));
}
else {
echo json_encode(array("status"=>"error", "error"=>"une erreur est survenue..."));
}

mysql_query($updateperso4, $cnx) or die(mysql_error());
mysql_close();

}

elseif ($pos1!==0 && $pos2===0) {

$updateperso5 = "UPDATE `Operations n°` SET `adjoint`=\"$adjoint\" WHERE `cmsperso`='' AND `chefdequart`=\"$chefdequart2\" AND `adjoint`=\"$adjoint2\"";

if($updateperso5) {
echo json_encode(array("status"=>"ok"));
}
else {
echo json_encode(array("status"=>"error", "error"=>"une erreur est survenue..."));
}

mysql_query($updateperso5, $cnx) or die(mysql_error());
mysql_close();

}

else {
echo "Ouppsss !";
}

}
}

当我将其中一个更新放入 phpmyadmin 时,更新工作和值将会更改,但在我的代码中该值不会更改。

当我在插入chefdequart和adjoint后尝试chefdequart时,firebug没有返回错误,如下: firebug

数据在视觉上发生了变化,但 phpmyadmin 中没有变化。

希望你能理解我。感谢大家。

最佳答案

主题由此解决

 if(cmsperso === undefined) { var cmsperso = $(this).closest('td').children('.textepersocms').html(); }
if(chefdequart === undefined) { var chefdequart = $(this).closest('td').children('.textepersocdq').html(); }
if(adjoint === undefined) { var adjoint = $(this).closest('td').children('.textepersoadj').html(); }

我测试我的变量是否未定义,并输入我需要的值,然后ajax返回该值

这很神奇。感谢您的帮助

关于php - 在ajax x-editable之后用条件更新php中的sql表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14867980/

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