logic help :)

#1
[eluser]sasori[/eluser]
as the title says, I need logic help, i mean code snippet LOL
- when I don't put anything on the form and submit it,cool it shows the validation_errors();
- and then on the 2nd click its shows the flashdata
but when I input any random characters that doesn't exist on db, am being redirected to a blank page LOL

here's my controller code
Code:
public function forgot()
  {
    $data['main_content'] = 'forgot_view';
    $data['title'] = 'Reset Password';
    $this->load->view('includes/template',$data);
  }

  public function reset()
  {
    $this->form_validation->set_rules('username','Username','required');
    if($this->form_validation->run() != FALSE)
    {
      $q = $this->member_model->getuser($this->input->post('username'));
      if($this->input->post('username') == $q)
        {
        $this->member_model->reset($this->input->post('username'));
        $this->session->set_flashdata('resetstat','You successfully reset your password');
        $data['title'] = "Reset Password";
        $data['main_content'] = 'new_password';
        $this->load->view('includes/template',$data);
        }
    }
    else
    {
    $this->session->set_flashdata('resetstat','its either we did not see your username in db or you typed it wrong');
    $this->forgot();
    }
  }

here's my model code

Code:
public function getuser($user)
  {
    $this->db->where('username',$user);
    $q = $this->db->get('user');
    if($q->num_rows == 1)
    {
    return $q;
    }
    else
    {
    return FALSE;
    }
  }

  public function reset($user)
  {
     $data = array('passwd'=> NULL);
     $this->db->where('username',$user);
     $q = $this->db->update('user',$data);
     if($this->db->affected_rows() === 1)
     {
        return TRUE;
     }
     else
     {
       return FALSE;
     }
  }

and here's my view code

Code:
<h2>Reset password</h2><br  />
&lt;?php $session = $this->session->flashdata('resetstat');
         if(isset($session)){ echo $session;} ?&gt;
&lt;?php echo validation_errors(); ?&gt;
&lt;?php echo form_open('user/reset'); ?&gt;
<br />
<table cellpadding="0" cellspacing="2" bgcolor="#cccccc" width="250" >
    <tr>
        <td>Enter Your Username</td><td>&lt;?php echo form_input(array('name'=>'username','maxlength'=>'16','size'=>'16')); ?&gt;</td>
    </tr>
    <tr>
        <td align="center" colspan="2">&lt;?php echo form_submit('submit','change password'); ?&gt;</td>
    </tr>
</table>

and here's the other view code

Code:
<h2>Reset password</h2><br  />
&lt;?php $session1 = $this->session->flashdata('resetstat');
        $session2 = $this->session->flashdata('newpass');
    if(isset($session)){ echo $this->session->flashdata('resetstat');}
    if(isset($session)){ echo $this->session->flashdata('newpass');}

?&gt;
&lt;?php echo form_open('user/newpass'); ?&gt;
<table cellpadding="0" cellspacing="2" bgcolor="#cccccc" width="250" >
    <tr>
        <td>New Password</td><td>&lt;?php echo form_password(array('name'=>'passwd','maxlength'=>'32','size'=>'16')); ?&gt;</td>
    </tr>
    <tr>
        <td>Confirm Password</td><td>&lt;?php echo form_password(array('name'=>'passwd2','maxlength'=>'32','size'=>'16')); ?&gt;</td>
    </tr>
    <tr>
        <td align="center" colspan="2">&lt;?php echo form_submit('submit','change password'); ?&gt;</td>
    </tr>
</table>

what should I do?

#2
[eluser]danmontgomery[/eluser]
Code:
$q = $this->member_model->getuser($this->input->post('username'));

You're comparing a string to a db result, which will always fail, and provide no else to that if.

Code:
public function getuser($user)
  {
    $this->db->where('username',$user);
    $q = $this->db->get('user');
    if($q->num_rows == 1)
    {
      return $q->row()->username;
    }
    else
    {
      return FALSE;
    }
  }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.