Codeigniter会话变量,表单,更新数据库值

时间:2017-02-08 20:14:37

标签: php forms codeigniter

我一直在处理一个表格,在那里我检索用户的所有细节并将其填入表格中的文本字段。我有一个会话正在运行,但文本字段中的值我直接从数据库中调用它们并将它们发布到我的视图中

查看

<?php
                                foreach ($getrecord as $key => $getdetails)
                                {
                                    ?>
                                <input type="text" name="username" value="<?= $getdetails['s_county']?>"> <?php } ?>

模型

 public function getstudent($getstudent)
  {

    $this->db->select('*');
    $this->db->from('qcs_student');
    $this->db->where('student_id', $getstudent);
    $query= $this->db->get();

    return $query->result_array();
}

控制器

public function myprofile()
  {
    $mydata = $this->session->all_userdata();
    $getstudent = $mydata['student_id'];

    $data['getrecord'] = $this->model_student->getstudent($getstudent);

        $this->load->view('student/header', array('logged_in'=>$this->logged_in));
        $this->load->view('student/myprofile', $data, array('logged_in' => $this->logged_in));
        $this->load->view('student/footer');

}

现在问题出现在从textifield更新用户详细信息s_username之后,它会保存对数据库的更改但文本字段值不会更改,即使我重新加载页面时更改了相同的用户名10次在视图相同的情况下,文本字段由相同的值填充,而不是数据库中的更新值。

奇怪的是,我已经交叉检查了我的代码,仍然无需编辑,因为所有内容似乎都很好,但文本字段仍显示相同的值,而不是从我的数据库中刷新并替换最新更新的s_username

1 个答案:

答案 0 :(得分:0)

尝试

import UIKit

class CharacteristicsViewController: UIViewController, UINavigationControllerDelegate {


@IBOutlet weak var confidenceButton: UIButton!
@IBOutlet weak var humbleButton: UIButton!
@IBOutlet weak var creativeButton: UIButton!
@IBOutlet weak var athleticButton: UIButton!
@IBOutlet weak var loyalButton: UIButton!
@IBOutlet weak var intelligenceButton: UIButton!
@IBOutlet weak var punctualButton: UIButton!
@IBOutlet weak var kindButton: UIButton!
@IBOutlet weak var braveButton: UIButton!


override func viewDidLoad() {
    super.viewDidLoad()

    //HIDE/SHOW NAVIGATION BAR
    self.navigationController?.isNavigationBarHidden = false

    //1. CONFIDENCE BUTTON SETTINGS
    confidenceButton.setImage(UIImage(named: "confidentnor"), for: UIControlState.normal)
    confidenceButton.setImage(UIImage(named: "confidenthigh"), for: UIControlState.selected)
    confidenceButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //2. HUMBLE BUTTON SETTINGS
    humbleButton.setImage(UIImage(named: "humblenor"), for: UIControlState.normal)
    humbleButton.setImage(UIImage(named: "humblehigh"), for: UIControlState.selected)
    humbleButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //3. CREATIVE BUTTON SETTINGS
    creativeButton.setImage(UIImage(named: "creativenor"), for: UIControlState.normal)
    creativeButton.setImage(UIImage(named: "creativehigh"), for: UIControlState.selected)
    creativeButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //4. ATHLETIC BUTTON SETTINGS
    athleticButton.setImage(UIImage(named: "athleticnor"), for: UIControlState.normal)
    athleticButton.setImage(UIImage(named: "athletichigh"), for: UIControlState.selected)
    athleticButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //5. LOYAL BUTTON SETTINGS
    loyalButton.setImage(UIImage(named: "loyalnor"), for: UIControlState.normal)
    loyalButton.setImage(UIImage(named: "loyalhigh"), for: UIControlState.selected)
    loyalButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //6. INTELLIGENT BUTTON SETTINGS
    intelligenceButton.setImage(UIImage(named: "intelligentnor"), for: UIControlState.normal)
    intelligenceButton.setImage(UIImage(named: "intelligenthigh"), for: UIControlState.selected)
    intelligenceButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //7. PUNCTUAL BUTTON SETTINGS
    punctualButton.setImage(UIImage(named: "punctualnor"), for: UIControlState.normal)
    punctualButton.setImage(UIImage(named: "punctualhigh"), for: UIControlState.selected)
    punctualButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //8. KIND BUTTON SETTINGS
    kindButton.setImage(UIImage(named: "kindnor"), for: UIControlState.normal)
    kindButton.setImage(UIImage(named: "kindhigh"), for: UIControlState.selected)
    kindButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    //9. BRAVE BUTTON SETTINGS
    braveButton.setImage(UIImage(named: "bravenor"), for: UIControlState.normal)
    braveButton.setImage(UIImage(named: "bravehigh"), for: UIControlState.selected)
    braveButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)

}

//BUTTON HIGHLIGHT FUNCTION
func buttonTapped(sender:UIButton) {
    sender.isSelected = !sender.isSelected; }


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()


}

}