Hi all newbie here :) Don't know if this is correct title, so sorry if not...
I'm trying to input data from one table to another for right user
controller:
function Admin(){
$user = $this->input->post('username'); //there is one text field in view page were you input username
$this->user->getEmail($user);
if($this->user->getUser($user)){
$this->user->Input_Admin();
$this->Success();
}
$this->Fail();
}
model:
function Input_Admin(){
$k = array(
'Name' => $this->input->post('username'),
'Email' => $this->input->post('Email'),
);
$a = $this->db->insert('admin', $k);
return $a;
}
function getEmail($user){
$this->db->select('Email');
$this->db->where('username', $user);
$q = $this->db->get('users');
if($q->num_rows > 0){
return $q->result();
}
return FALSE;
}
There is 3 fields in admin table id, name, email... the function for name is working like a charm but for email always input 0.... so what i'm doing wrong?
As req here is view:
<form name="info" method="post" action="<?php echo base_url(); ?>index.php/user_controler/admin">
<table width="500" border="0" cellspacing="1" cellpadding="1" align="center" bgcolor="#FFCC99">
<tr>
<td width="25%">Username:</td>
<td><input type="text" name="username" size="30"></td>
</tr>
<tr>
<td colspan="6">
<div align="center">
<input type="submit" name="Confirm" value="Confirm">
<input type="reset" name="Cancel" value="CANCEL">
</div>
</td>
</tr>
</table>
</form>
where is <input type="text" name="Email" size="30">
?
you have not that in html, so you get 0 value
put that in html , so the post request will send email too to your controller ;)
just to make it clear:
$k = array(
'Name' => $this->input->post('username'), //needs <input name="username"/> in html
'Email' => $this->input->post('Email'), //needs <input name="Email"/> in html
);
one more tip use this:
<?php echo site_url('user_controller/admin'); ?>
instead of
<?php echo base_url(); ?>index.php/user_controler/admin
more comfortable ,easy to read ;)
You can then try this if you want user email from db:
function Admin(){
$user = $this->input->post('username'); //there is one text field in view page were you input username
$results = $this->user->getEmail($user);
if($this->user->getUser($user)){
$this->user->Input_Admin($results);
$this->Success();
}
$this->Fail();
}
function Input_Admin($data){
$k = array(
'Name' => $this->input->post('username'),
'Email' => $data->email,
);
$a = $this->db->insert('admin', $k);
return $a;
}
function getEmail($user){
$this->db->select('Email');
$this->db->where('username', $user);
$q = $this->db->get('users');
if($q->num_rows > 0){
return $q->row();
}
return FALSE;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.