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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?