php - $statement 执行并返回 true 但不影响 mysql 表中的任何行
问题描述
我的添加操作代码中的插入语句运行完美,并且还在我的表中插入值,但更新语句运行不正常。我得到的错误代码和错误信息是:00000 发生错误:00000:: 我还尝试在单引号内添加我的 :GroupName 和所有其他人,但仍然是同样的问题。这是我的插入代码:
<?php
include('connection.php');
include('function.php');
if(isset($_POST["operation"]))
{
if($_POST["operation"] == "Add")
{
$Diwaliinvites = false;
$SubscribedToMailingList = false;
if(isset($_POST['Diwaliinvites']))
{
$Diwaliinvites = true;
}
else
{
$Diwaliinvites = false;
}
if(isset($_POST['SubscribedToMailingList']))
{
$SubscribedToMailingList = true;
}
else
{
$SubscribedToMailingList = false;
}
$Datetimestamp = date('Y-m-d H:i:s');
$statement = $connection->prepare("
INSERT INTO tab_organizers (GroupName, ContactName, Address1, Address2, City,
Province, PostalCode, Country, Title, Telephone1, Telephone2, FaxNumber, SchoolGeneralEmail, Email,
SubscribedToMailingList, HowDidYouHear, Comments, Datetimestamp, Diwaliinvites)
VALUES
(:GroupName, :ContactName, :Address1, :Address2, :City, :Province, :PostalCode,
:Country, :Title, :Telephone1, :Telephone2, :FaxNumber, :SchoolGeneralEmail, :Email,
:SubscribedToMailingList, :HowDidYouHear, :Comments, :Datetimestamp, :Diwaliinvites)
");
$result = $statement->execute(
array(
':GroupName' => $_POST["GroupName"],
':ContactName' => $_POST["ContactName"],
':Address1' => $_POST["Address1"],
':Address2' => $_POST["Address2"],
':City' => $_POST["City"],
':Province' => $_POST["Province"],
':PostalCode' => $_POST["PostalCode"],
':Country' => $_POST["Country"],
':Title' => $_POST["Title"],
':Telephone1' => $_POST["Telephone1"],
':Telephone2' => $_POST["Telephone2"],
':FaxNumber' => $_POST["FaxNumber"],
':SchoolGeneralEmail' => $_POST["SchoolGeneralEmail"],
':Email' => $_POST["Email"],
':SubscribedToMailingList' => $SubscribedToMailingList,
':HowDidYouHear' => $_POST["HowDidYouHear"],
':Comments' => $_POST["Comments"],
':Datetimestamp' => $Datetimestamp,
':Diwaliinvites' => $Diwaliinvites
)
);
if(!empty($result))
{
echo 'Data Inserted';
}
else{
echo 'Data Not Inserted';
}
}
if($_POST["operation"] == "Edit")
{
$Datetimestamp = date('Y-m-d H:i:s');
$Diwaliinvites = false;
$SubscribedToMailingList = false;
if(isset($_POST['Diwaliinvites']))
{
$Diwaliinvites = true;
// echo $Diwaliinvites;
}
if(isset($_POST['SubscribedToMailingList']))
{
$SubscribedToMailingList = true;
// echo $SubscribedToMailingList;
}
try {
$statement = $connection->prepare(
"
UPDATE tab_organizers SET
GroupName= :GroupName ,
ContactName= :ContactName,
Address1= :Address1,
Address2= :Address2,
City= :City,
Province= :Province,
PostalCode= :PostalCode,
Country= :Country,
Title= :Title,
Telephone1= :Telephone1,
Telephone2= :Telephone2,
FaxNumber= :FaxNumber,
SchoolGeneralEmail= :SchoolGeneralEmail,
Email= :Email,
SubscribedToMailingList= :SubscribedToMailingList,
HowDidYouHear= :HowDidYouHear,
Comments= :Comments,
Datetimestamp= :Datetimestamp,
Diwaliinvites= :Diwaliinvites
WHERE OrganizerID = :OrganizerID;
");
$statement -> bindparam(':GroupName', $_POST["GroupName"]);
$statement -> bindparam(':ContactName', $_POST["ContactName"]);
$statement -> bindparam(':Address1', $_POST["Address1"]);
$statement -> bindparam(':Address2', $_POST["Address2"]);
$statement -> bindparam(':City', $_POST["City"]);
$statement -> bindparam(':Province', $_POST["Province"]);
$statement -> bindparam(':PostalCode', $_POST["PostalCode"]);
$statement -> bindparam(':Country', $_POST["Country"]);
$statement -> bindparam(':Title', $_POST["Title"]);
$statement -> bindparam(':Telephone1', $_POST["Telephone1"]);
$statement -> bindparam(':Telephone2', $_POST["Telephone2"]);
$statement -> bindparam(':FaxNumber', $_POST["FaxNumber"]);
$statement -> bindparam(':SchoolGeneralEmail', $_POST["SchoolGeneralEmail"]);
$statement -> bindparam(':Email', $_POST["Email"]);
$statement -> bindparam(':HowDidYouHear', $_POST["HowDidYouHear"]);
$statement -> bindparam(':Comments', $_POST["Comments"]);
$statement -> bindparam(':Datetimestamp', $Datetimestamp);
$statement -> bindparam(':SubscribedToMailingList', $SubscribedToMailingList);
$statement -> bindparam(':Diwaliinvites', $Diwaliinvites);
$statement -> bindparam(':OrganizerID', $_POST["OrganizerID"]);
$result = $statement->execute();
// array(
// ':GroupName' => $_POST["GroupName"],
// ':ContactName' => $_POST["ContactName"],
// ':Address1' => $_POST["Address1"],
// ':Address2' => $_POST["Address2"],
// ':City' => $_POST["City"],
// ':Province' => $_POST["Province"],
// ':PostalCode' => $_POST["PostalCode"],
// ':Country' => $_POST["Country"],
// ':Title' => $_POST["Title"],
// ':Telephone1' => $_POST["Telephone1"],
// ':Telephone2' => $_POST["Telephone2"],
// ':FaxNumber' => $_POST["FaxNumber"],
// ':SchoolGeneralEmail' => $_POST["SchoolGeneralEmail"],
// ':Email' => $_POST["Email"],
// ':SubscribedToMailingList' => $SubscribedToMailingList,
// ':HowDidYouHear' => $_POST["HowDidYouHear"],
// ':Comments' => $_POST["Comments"],
// ':Datetimestamp' => $Datetimestamp,
// ':Diwaliinvites' => $Diwaliinvites,
// ':OrganizerID' => $_POST["OrganizerID"]
// )
// );
$statement->closeCursor();
$number_filter_row = $statement->rowCount();
$done = $statement !== false ? true : false;
}
catch(PDOException $e) {
console.log($e->getMessage(), $e->getCode(), array('exception' => $e));
}
if($result === false)
{
echo 'Data Not Updated';
echo $number_filter_row;
echo $done;
echo $statement->errorCode();
// echo PDO::errorInfo();
echo 'Error occurred:'.implode(":",$connection->errorInfo());
}
else{
echo 'Data Updated';
echo $number_filter_row;
echo $done;
echo $statement->errorCode();
// echo PDO::errorInfo();
echo 'Error occurred:'.implode(":",$connection->errorInfo());
}
}
}
?>
编辑1:这是我在js中编辑按钮ajax函数的代码:
$(document).on('click', '.edit_data', function(){
var OrganizerID = $(this).attr("id");
alert(OrganizerID);
$.ajax({
url:"fetch.php",
method:"post",
data:{OrganizerID:OrganizerID},
dataType:"json",
success:function(data){
// alert(data);
// $('input[name="Diwaliinvites"][value="'+ID+'"]').prop('checked',true);
$('#Datetimestamp').val(data.Datetimestamp);
$('#GroupName').val(data.GroupName);
$('#ContactName').val(data.ContactName);
$('#Address1').val(data.Address1);
$('#Address2').val(data.Address2);
$('#City').val(data.City);
$('#Province').val(data.Province);
$('#PostalCode').val(data.PostalCode);
$('#Country').val(data.Country);
$('#Title').val(data.Title);
$('#Telephone1').val(data.Telephone1);
$('#Telephone2').val(data.Telephone2);
$('#FaxNumber').val(data.FaxNumber);
$('#SchoolGeneralEmail').val(data.SchoolGeneralEmail);
$('#Email').val(data.Email);
$('#HowDidYouHear').val(data.HowDidYouHear);
$('#Comments').val(data.Comments);
$('#Diwaliinvites').val(data.Diwaliinvites);
$('#SubscribedToMailingList').val(data.SubscribedToMailingList);
$('#visitoraddmodal').modal("show");
$('.modal-title').text("Edit User");
$('#OrganizerID').val(OrganizerID);
$('#action').val("Edit");
$('#operation').val("Edit");
}
});
});
我得到的 OrganizerID 是 1064。
解决方案
我找到了答案。问题是因为我试图在我的索引文件中包含我的 delete_modal.php 文件。我不知道它们是如何相关的,但这解决了我的问题。
推荐阅读
- python - 有没有办法确定传递给函数的参数是在python中分配还是文字?
- python - 在excel中插入日期公式得到#name?用python插入后出错
- visual-studio - 重新启动 Shell Visual Studio
- reactjs - 使用 refs 从父组件向子组件 div 添加/删除类
- c++ - 查找输入值的最大值和最小值
- google-analytics - 如何向 gtag 发送事件?
- angular - Jasmine Marbles 的单元测试不包括代码覆盖率报告中的代码
- javascript - 从 firebase 数据库存储数组
- ms-word - 尝试使用 Office js 插件打开对象浏览器对话框
- javascript - 与nodejs和mysql的连接