我想更新我的数据如果它是假的它将返回editadmin.php但是如果它成功它将转到successupdateadmin.php但是当我点击按钮时,没有任何反应,我的模型方法是updateadmin
这是我的控制器与会话
function index(){
if ($this->session->userdata('logged_in')) {
$session_data = $this->session->userdata('logged_in');
$data['Id'] = $session_data['Id'];
$data['Username'] = $session_data['Username'];
$data['Name'] = $session_data['Name'];
$data['Password'] = $session_data['Password'];
$data['Email'] = $session_data['Email'];
$data['Gender'] = $session_data['Gender'];
$this->load->view('EditAdmin', $data);
} else {
redirect('welcome', 'refresh');
}
}
function updateadminz() {
if (isset($_POST['Submit'])){
$this->form_validation->set_rules('Username', 'Username', 'trim|required');
$this->form_validation->set_rules('Name', 'Name', 'trim|required');
$this->form_validation->set_rules('Password', 'Password', 'trim|required');
$this->form_validation->set_rules('Email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('Gender', 'Gender', 'trim|required|alpha|max_length[6]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('EditAdmin');
} else {
$id = $this->input->post('Id');
$username = $this->input->post('Username');
$name=$this->input->post('Name');
$password = $this->input->post('Password');
$email = $this->input->post('Email');
$gender = $this->input->post('Gender');
}
$this->load->model('model_adminlogin');
$result=$this->model_adminlogin->updateadmin($id, $username, $name, $password, $email, $gender);
if($result == True) {
$this->load->view('successfullyupdateadmin');
} else {
return false;
}
}
}
这是我的模特
function updateadmin( $id, $username, $name, $password, $email, $gender) {
$data = array(
'Username' => $username,
'Name' => $name,
'Password' => $password,
'Email' => $email,
'Gender' => $gender
);
$this->db->where('Id', $id);
$this->db->update('admin',$data);
}
这是我的观点
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title>Edit Admin</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Edit Admin,Online High School Enrollment">
<meta name="author" content="NMSC, Bernal Developers">
<?php echo link_tag('images/icon1.png', 'NMSC Icon', 'image/ico'); ?>
<link href="<?php echo base_url("dist/css/bootstrap.css"); ?>" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url("assets/css/bootstrap-theme.css"); ?>" type="text/css"/>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="<?php echo site_url("adminoption/index") ?>"><span class="glyphicon glyphicon-menu-left"></span> Back </a>
</div>
<div>
<p class="nav navbar-text "> <span class="glyphicon glyphicon-user"></span><?php echo "  " .$Username ;?></p>
<ul class="nav navbar-nav navbar-right">
<li><a href="<?php echo site_url("home/logout") ?>"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</div>
</div>
</nav>
<h3 class="giv">Edit Admin</h3>
<div class="wrap">
<form action="<?php echo site_url("editadmin/updateadminz") ?>" method="POST">
<label class="label-info input-lg"> Id:</label> <input class="" type="text" name="Id" value="<?php echo $Id ?>" readonly=""> <br>
<label class= "label-info input-lg ">Username:</label>
<input type="text" name="Username" id="Username" value="<?php echo $Username; ?>" size="70"><br>
<label class="label-info input-lg"> Name:</label>
<input type="text" name="Name" id="Name" value="<?php echo $Name; ?>" size="70"><br>
<label class="label-info input-lg"> Password:</label>
<input type="text" name="Password" id="Password" value="<?php echo $Password; ?>" size="70" ><br>
<label class="label-info input-lg"> Email:</label> <input type="email" name="Email" id="Email" value="<?php echo $Email; ?>" size="70"><br>
<label class="label-info input-lg"> Gender:</label>
<input type="text" name="Gender" id="Gender" value="<?php echo $Gender; ?>" size="70"><br>
<br>
<button type="submit" name="Submit" class="btn btn-info z" data-dismiss="modal">Save</button>
</form>
</div>
<script src="<?php echo base_url("js/jquery-2.1.4.js"); ?>" type="text/javascript"></script>
<script src="<?php echo base_url("dist/js/bootstrap.js"); ?>" type="text/javascript"></script>
</body>
</html>
答案 0 :(得分:0)
您可以将此功能作为控制器功能:
function updateadminz() {
if (isset($_POST['Submit'])){
$this->form_validation->set_rules('Username', 'Username', 'trim|required');
$this->form_validation->set_rules('Name', 'Name', 'trim|required');
$this->form_validation->set_rules('Password', 'Password', 'trim|required');
$this->form_validation->set_rules('Email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('Gender', 'Gender', 'trim|required|alpha|max_length[6]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('EditAdmin');
} else {
$id = $this->input->post('Id');
$data = Array(
'Name' => $this->input->post('Name'),
'Password' => $this->input->post('Password'),
'Email' => $this->input->post('Email'),
'Gender' => $this->input->post('Gender')
);
$this->db->where('Id', $id);
$this->db->update('admin',$data);
if (!empty($data)) {
$this->load->view('successfullyupdateadmin');
}
}
}
}