Welcome Guest, Not a member yet? Register   Sign In
how to make update function
#1

[eluser]yudahebat[/eluser]
please help me... I dont know how to update my database
where I put the function??
model or controller???
#2

[eluser]TheFuzzy0ne[/eluser]
The model. The model is responsible for handling your stored data. The controller should call the model.
#3

[eluser]pistolPete[/eluser]
I assume you want to update a specific database entry, correct?
You should put any database related functions into the model.

If you use Active Record, there is an update() function:
Code:
$this->db->update();

Read the user guide.
#4

[eluser]yudahebat[/eluser]
thx.. can you give me an example??
I'm beginner

the situation :
I have a form that update only password
the form is
username : admin
password :....
confirm paswword :...

update | reset

how to update??
#5

[eluser]TheFuzzy0ne[/eluser]
It would help if we could see your controller and view.
#6

[eluser]yudahebat[/eluser]
this is my controller
Code:
<?php
class Adminpage extends Controller
{
    var $base;
    var $css;
    
    function Adminpage()
    {
        parent::Controller();
    }
    function index()
    {
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css1');
        $data['css1'] = $this->css;
        $data['base'] = $this->base;
        $data['myrobots'] = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | adminlogin';
    
        //This assumes you used the sample MySQL table
        $user_table = 'admin';
        
        //Load the URL helper
        $this->load->helper('url');
        
        $this->load->view('adminlogin',$data);    
    }    
    
    function admin()
    {
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css1');
        $data['css1'] = $this->css;
        $data['base'] = $this->base;
        $data['myrobots'] = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | admin';
    
        //This assumes you used the sample MySQL table
        $user_table = 'admin';
        
        //Load the URL helper
        $this->load->helper('url');
        
        $this->load->view('admin',$data);    
    }    
    function login()
    {
        //Load
        $this->load->helper('url');
        $this->load->library('validation');
        
        //Check incoming variables
        $rules['login_username']    = "required|min_length[4]|max_length[32]|alpha_dash";
        $rules['login_password']    = "required|min_length[4]|max_length[32]|alpha_dash";        

        $this->validation->set_rules($rules);

        $fields['login_username'] = 'Username';
        $fields['login_password'] = 'Password';
        
        $this->validation->set_fields($fields);
                
        if ($this->validation->run() == false) {
            /**/
            //If you are using OBSession you can uncomment these lines
            $flashdata = array('error' => true, 'error_text' => $this->validation->error_string);
            $this->session->set_flashdata($flashdata);
            $this->session->set_flashdata($_POST);
            /**/
            redirect('/adminpage/');            
        } else {
            //Login to account
            if($this->simplelogin->login($this->input->post('login_username'), $this->input->post('login_password'))) {
                /**/
                //If you are using OBSession you can uncomment these lines
                $flashdata = array('success' => true, 'success_text' => 'Login Successful!');
                $this->session->set_flashdata($flashdata);
                /**/
                redirect('/adminpage/');    
            } else {
                /**/
                //If you are using OBSession you can uncomment these lines
                $flashdata = array('error' => true, 'error_text' => 'There was a problem logging into the account.');
                $this->session->set_flashdata($flashdata);
                $this->session->set_flashdata($_POST);
                /**/
                redirect('/adminpage/');            
            }            
        }
    }

    function delete($user_id)
    {
        /* This method can delete your current user account
         * and you will still be logged in until you click
         * the logout button (then you won't be able to login again')
         */
        
        //Load
        $this->load->helper('url');

        if($this->simplelogin->delete($user_id)) {
            /*
            //If you are using OBSession you can uncomment these lines
            $flashdata = array('success' => true, 'success_text' => 'Deletion Successful!');
            $this->session->set_flashdata($flashdata);
            */
            redirect('/adminpage/');    
        } else {
            /*
            //If you are using OBSession you can uncomment these lines
            $flashdata = array('error' => true, 'error_text' => 'There was a problem creating the account.');
            $this->session->set_flashdata($flashdata);
            $this->session->set_flashdata($_POST);
            */
            redirect('/adminpage/');            
        }            
        
    }

    function logout()
    {
        //Load
        $this->load->helper('url');

        //Logout
        $this->simplelogin->logout();
        redirect('/adminpage/');
    }
    
}
#7

[eluser]yudahebat[/eluser]
this is my view
Code:
<?php  $this->load->view('header');  ?>

<?php      //Load the URL helper
        $this->load->helper('url');
        $user_table = 'admin';
?>

&lt;?php echo '<div id="jdl_adm2">';?&gt;
            
    <img src="&lt;?php echo " width="300" height="50" />    
    &lt;?php
    echo '</div>';
            echo '<div id="menu">';
                echo '<ul>';
                    echo '/<li>'; echo anchor('adminpage/admin','Data Admin'); echo '</li>';
                    echo '/<li>'; echo anchor('adminpage/adm_jns_kend','Data Jenis Kendaraan');echo '</li>';
                    echo '/<li>'; echo anchor('adminpage/adm_kend','Data Kendaraan');echo '</li>';
                    echo '/<li>'; echo anchor('adminpage/adm_reservasi','Data Reservasi');echo '</li>';
                    echo '/<li>'; echo anchor('adminpage/adm_news','Data News');echo '</li>';
                    echo '/<li>'; echo anchor('adminpage/adm_driver','Data Driver');echo '</li>/';
                    
                echo '</ul>';
            echo '</div>';
            echo '<div id="infologin">';
        
                //BOF Status Info
                        if($this->session->userdata('logged_in')) {
                            echo '<h4>User logged in as ' . $this->session->userdata('username');
                            echo ' | ';
                            echo anchor('/adminpage/logout/','logout');echo '</h4>';
                        }
                        else
                        {
                            echo '<h4>User not logged in';
                            echo ' | ';
                            echo anchor('/adminpage/logout/','login');echo '</h4>';
                        }

                        
                //EOF Status Info
                
            echo '</div>';
            echo '<div class="right"></div>';        
                echo '<h1 style="color:#E7541A;">Form Admin </h1>
                    &lt;form id="myform" class="cssform" action="' . site_url('/adminpage/update/') .'"&gt;

                        <p>
                        <label for="user">Username</label>';
                        echo '<label for="user" style="color:#E7541A;">'. $this->session->userdata('username').'</label>';
                        echo '</p>
                        
                        <p>
                        <label for="emailaddress">Change Password</label>
                        &lt;input type="text" id="emailaddress" value="" /&gt;
                        </p>
                        
                        <p>
                        <label for="emailaddress">Confirm Password</label>
                        &lt;input type="text" id="emailaddress" value="" /&gt;
                        </p>
                        
                        <p></p>
                                                
                        <div style="margin-left: 160px;">
                        &lt;input type="submit" id="submitbutton1" value="Update" /&gt;
                        &lt;input type="reset" id="submitbutton1" value="Reset" /&gt;
                        </div>
                    &lt;/form&gt;';
                    
                echo '<div class="both"></div>';
                
                echo '<div id="dt_tabel">';
                
                //BOF User table
                if($this->session->userdata('logged_in'))
                {
                    //Grab user data from database
                    $query = $this->db->select('id_admin, username');
                    $query = $this->db->get($user_table);
                    $user_array = $query->result_array();
                    
                    if(count($user_array) > 0)
                    {
                
                        echo '<h1 style="color:#E7541A;">Form Admin </h1>';
                            echo '<table width="300" border="0" cellpadding="0" cellspacing="0" class="tabel" >';
                                  echo '<tr>';
                                    echo '<td width="160" class="tabel"><p>ID</p></td>';
                                    echo '<td width="240" class="tabel"><p>USERNAME<p></td>';
                                  echo '</tr>';
                                  foreach($user_array as $ua)
                                  {
                                      echo '<tr>';
                                        echo '<td  class="tabel">';
                                        echo '<p>';
                                            echo $ua['id_admin'];
                                        echo '</p>';
                                        echo '</td>';
                                        echo '<td class="tabel">';
                                        echo '<p>';
                                            echo $ua['username'];
                                        echo '</p>';
                                        echo '</td>';
                                      echo '</tr>';
                                  }
                            echo '</table>';
                    }
                }
                        
                        echo '</div>';
                
?&gt;

&lt;?php  $this->load->view('footer');
#8

[eluser]yudahebat[/eluser]
what should I do to make update function???
do I make a controller that call model for update function???
#9

[eluser]TheFuzzy0ne[/eluser]
Your controller doesn't seem to tie in with what you're asking.

Please [url="http://ellislab.com/forums/viewthread/107773/"]check out this thread[/url]. It should help you gain a deeper knowledge of how to build applications with CodeIgniter.

But yes, you need to create a function called something like "change_password", and that function should do any validation, call the model if necessary and load the view.
#10

[eluser]yudahebat[/eluser]
thx
I'll check the thread that you give to me




Theme © iAndrew 2016 - Forum software by © MyBB