Welcome Guest, Not a member yet? Register   Sign In
CRUD Tutorial Help...
#1

[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>

&lt;!--&lt;?PHP foreach ($records as $row) { echo ' --&gt;

<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>
  
  &lt;form method="post" action="'.base_url().'index.php/crud/update_record_with_id/'. $row-&gt;user_id.'" class="blah"/&gt;  

&lt;!--';} ?&gt; End of PHP--&gt;


&lt;!--&lt;?PHP foreach ($records as $row) { echo ' --&gt;
  <div class="form_div">
   &lt;input type="hidden" name="Language" value="'.$row-&gt;user_id.'"  
  &lt;/div>
&lt;!--';} ?&gt; End of PHP--&gt;

  <div class="form_div">
  New User Name: &lt;input class="login_password" type="text"  name="username"  value="&lt;?php echo set_value('text'); ?&gt;"&gt;
  </div>

  <div class="error">&lt;?php echo form_error('username'); ?&gt;
  </div>

  <div class="login_div_email">
  New Email: &lt;input class="login_email" type="text"  name="email"  value="&lt;?php echo set_value('email'); ?&gt;"&gt;
  </div>

  <div class="error">&lt;?php echo form_error('email'); ?&gt;
  </div>


&lt;!-- &lt;?PHP foreach ($records as $row) { echo ' --&gt;

  <a href=".base_url().'index.php/crud/update_record_with_id/'. $row-&gt;user_id.'">
  <div class="login_button_div">
  &lt;input class="blue_button" type="submit"  name="submit"  value="Submit" /&gt;
  </a>

&lt;!-- ';} ?&gt; End of PHP --&gt;

  </div>

  &lt;/form&gt;
</div>

</center>


view_update_success(Which all shows-up fine--except the db hasn't been changed)
Code:
<p>
<center>
  <br>
  <div>
  &lt;?echo $username;?&gt;
  </div>

  <br>
  at
  <br>
  <br>

  <div>
  &lt;?echo $email;?&gt;
  </div>

  <br>
  with User ID
  <br>
  <br>

  <div>
  &lt;?echo $user_id;?&gt;
  </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);
}




Theme © iAndrew 2016 - Forum software by © MyBB