donoworuq450547191 2010-12-05 21:09
浏览 94
已采纳

在更新后直接检索记录时,PHP页面不显示来自MySQL的更新数据

I have a simple page in a PHP/MySQL web application that lets admin users edit HTML template e-mails (stored in the database). Essentially to edit a template the user types into a textarea and submits a form which posts back to the same page.

When the form is submitted, a PHP function gets called that updates the record in the database by means of a parameterised query to a MySQL stored function.

Finally the record is retreived from the database and the information is displayed on the page - this step also happens when the page is being displayed for the first time.

The problem I am having is that although the record is being updated in the database before it is retrieved for display, the page is still displaying the old data from before the update when it is rendered. Other things on the page, such as the banner message saying the update was successful DO get updated, so I don't think it's a browser caching problem. Adding the line: sleep(1); after the record update solves the problem so the page shows the updated record, but for performance reasons this isn't ideal, and I don't understand why this problem is happening in the first place.

Here is the PHP code from the top of the page:

require_once('includes/global.php');
require_once('includes/emailtemplateutils.php');

$strMsg = '';

$lngEmailTemplatePK = ConvertToString($_GET['key'], 0);

if (ConvertToString($_POST['hdnSave']) == '1')
{

    $strFromAddress = ConvertToString($_POST['txtFromAddress']);
    $strSubjectLine = ConvertToString($_POST['txtSubjectLine']);
    $strBodyHTML = ConvertToString($_POST['txtBodyHTML']);

    if (EmailTemplate_Update($lngEmailTemplatePK, $strFromAddress, $strSubjectLine, $strBodyHTML))
    {

        $strMsg = FormatMsg('E-mail template updated.');

    }
    else
    {

        $strMsg = FormatErrorMsg('Could not save e-mail template!');

    }

}

$objEmailTemplate = EmailTemplate_Display($lngEmailTemplatePK);

This is the code of the EmailTemplate_Update() function which actually does the update:

function EmailTemplate_Update($lngEmailTemplatePK, $strFromAddress, $strSubjectLine, $strBodyHTML)
{

    $objConn = new mysqli(cstrGlobal_DbServer, cstrGlobal_DbUsername, cstrGlobal_DbPassword, cstrGlobal_DbCatalog);

    if (mysqli_connect_errno())
    {
        printf("Connect failed: %s
", mysqli_connect_error());
        exit();
    }

    $strQuery = "SELECT srf_EmailTemplate_Update(?, ?, ?, ?)";

    $objStmt = $objConn->prepare($strQuery);

    $objStmt->bind_param('isss', $lngEmailTemplatePK, EmptyToNull($strFromAddress), EmptyToNull($strSubjectLine), EmptyToNull($strBodyHTML));

    $objStmt->execute();

    $objStmt->bind_result($lngRetVal);

    $objStmt->fetch();

    $objStmt->close();

    $objConn->close();

    return $lngRetVal == 1;

}

The function for retrieving the record for display is a bit more convoluted but essentially just brings back the record as an object using mysqli fetch_object()

Please help.

  • 写回答

2条回答 默认 最新

  • dongliuzhuan1219 2010-12-11 12:15
    关注

    I eventually managed to solve this problem, though not in the way I would have planned. I managed to break the Linux install on the server due to various dependency issues after I attempted to upgrade MySQL and PHP. I ended up having to rebuild the server from scratch.

    The code in my original question now works as expected. I suspect the issue may have been that the InnoDB setting lines were commented out in the my.cnf file of the original MySQL installation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置