php - 表单提交更新数据库记录后,HTML文本框未更新
问题描述
我正在使用 CodeIgniter。在应用程序/视图/abc.php
<input type="text" name="company_profit" id="company_profit" value="<?php echo $form_data['company_profit']; ?>" >
在应用程序/控制器/Cde.php
$data['form_data'] = $form_data = $this->common->getOneRow("tbl_psb_setting","WHERE id=1");
if(isset($_POST) && count($_POST) > 0)
{
if($this->form_validation->run())
{
$up_data['company_profit'] = $this->input->post('company_profit');
$this->common->updateRecord('tbl_psb_setting',$up_data,"id=1");
}
}
当我单击提交按钮时,html 表单提交,数据库记录成功更新。但是为什么 HTML 文本框“company_profit”的值没有更新?我需要按 F5 刷新页面,然后才能看到文本框值已更新。
当我单击“提交”按钮时,我可以看到页面正在刷新,这意味着 html 表单提交了自动刷新页面,所以我猜在新记录更新到数据库之前,mysql 从分配给文本框的数据库中检索数据太快了?所以我尝试代码 php sleep(3); 等待 3 秒然后才开始从数据库中检索数据分配到文本框值,但失败,文本框仍然显示旧值。任何的想法?
解决方案
您在更新数据之前获取数据。只需像这样移动下面的 fetch :
if(isset($_POST) && count($_POST) > 0)
{
if($this->form_validation->run())
{
$up_data['company_profit'] = $this->input->post('company_profit');
$this->common->updateRecord('tbl_psb_setting',$up_data,"id=1");
}
}
$data['form_data'] = $form_data = $this->common->getOneRow("tbl_psb_setting","WHERE id=1");
推荐阅读
- sql - 验证数字oracle sql中的位数
- google-app-engine - AppEngine 从“/workspace”而不是“/srv”提供服务,但仅在某些实例上
- reactjs - 在 index.js 文件中的 React js 我们调用 reactDOM 渲染在括号中我们调用两个参数它是如何工作的
- java - 从 Android 上的自定义标签中选择文本时,Xamarin.Forms 应用程序崩溃
- php - 在 prod 模式下运行 sylius 项目
- node.js - 如何修复 webpack 错误:在 node.js (webpackEmptyContext) 上找不到模块
- python - 将数据转换为散点图等颜色
- python - 对数据框中的一列进行分组,并使用分组数据创建另一个数据框
- java - 来自 pmd:DataflowAnomalyAnalysis sslContext 的 Java UR-anomaly 和 DR-anomaly
- java - 遇到 HttpMessageNotReadableException 调用 getForEntity() restTemplate