[eluser]BoyBlue[/eluser]
I feel embarrassed about this, but I'm having trouble getting a variable to pass from my "View" all the way to the "Model". I've watched several tutorials and I still can't seem to replicate it "on my own". I hope someone can help me with it...
I'm trying to build a simple CRUD tutorial. In this example, I'm trying to have a User update a file by letting them select the file by ID, then it loads a new page that shows them all the Info for that ID and below that it allows them to enter new data into the form for updating that file. I can't get the ID to pass to the Model and so it isn't updating the Data.
thanks in advance
Here is the Controller function for the "Update":
Code:
function update_record_with_id()
{
$data = array(
//same as $_POST['username']
'user_id' => $this->uri->segment(3),
'username' => $this->input->xss_clean($this->input->post('username')),
'email' => $this->input->xss_clean($this->input->post('email')),
);
$this->load->model('model_users');
$this->model_users->update_record($data);
$this->load->view('update/view_update_success', $data);
$this->load->view('site/view_navbar');
}
Here are the Views relevant for the "Update":
view_update_record
Code:
<style type="text/css">
</style>
<center>
<div>
<h3 class="">
Update records in the Database
</h3>
</div>
<div>
<h4 class="">
The Person you selected corresponds with the following Information
</h4>
</div>
<!--<?PHP foreach ($records as $row) { echo ' -->
<hr />
<div>
<h3 class="">
User Name: '.$row->username .'
</h3>
</div>
<div>
<h3 class="">
User Email: '.$row->email .'
</h3>
</div>
<div>
<h5 class="">
Date and time User\'s record was last modified: '.$row->modified .'
</h5>
</div>
<div id="login_form">
<h3 class="">Input new information to update a record in the Database<h3>
<form method="post" action="'.base_url().'index.php/crud/update_record_with_id/'. $row->user_id.'" class="blah"/>
<!--';} ?> End of PHP-->
<!--<?PHP foreach ($records as $row) { echo ' -->
<div class="form_div">
<input type="hidden" name="Language" value="'.$row->user_id.'"
</div>
<!--';} ?> End of PHP-->
<div class="form_div">
New User Name: <input class="login_password" type="text" name="username" value="<?php echo set_value('text'); ?>">
</div>
<div class="error"><?php echo form_error('username'); ?>
</div>
<div class="login_div_email">
New Email: <input class="login_email" type="text" name="email" value="<?php echo set_value('email'); ?>">
</div>
<div class="error"><?php echo form_error('email'); ?>
</div>
<!-- <?PHP foreach ($records as $row) { echo ' -->
<a href=".base_url().'index.php/crud/update_record_with_id/'. $row->user_id.'">
<div class="login_button_div">
<input class="blue_button" type="submit" name="submit" value="Submit" />
</a>
<!-- ';} ?> End of PHP -->
</div>
</form>
</div>
</center>
view_update_success(Which all shows-up fine--except the db hasn't been changed)
Code:
<p>
<center>
<br>
<div>
<?echo $username;?>
</div>
<br>
at
<br>
<br>
<div>
<?echo $email;?>
</div>
<br>
with User ID
<br>
<br>
<div>
<?echo $user_id;?>
</div>
<br>
<div>
You have Successfully updated the data into the database!
<br>
<br>
(and brought it successfully back to this view...)
</div>
</center>
</p>
Here is the Model for the Update:
Code:
function update_record($data)
{
$user_id = $this->uri->segment(3);
$this->db->where('user_id', $user_id);
$this->db->update('users', $data);
}