• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update in codeigniter-3

#1
hi all,

I am having a problem with the page redirection in update and delete.
for update i have used form tag and have used a following code in form tag:-
form action= <?php echo form_open('admin/leads/updateleads?ids='.$row->l_id,['class'=>'form-horizontal panel' , 'method'=> 'POST']); ?>

my values are getting passed even update and delete is working but when i press update button it doesnt redirect me to previous page. and gives me error like:-

"Error Number: 1096
No tables used
SELECT *
Filename: C:\xampp\htdocs\CRM(10-10-16)\system\database\DB_driver.php
Line Number: 328"


My whole code is:-

VIEW:-


Code:
[code][color=#4f5155][size=small]<div class="row">
[/size][/color]
 <section class="content-header">
 <div class="col-lg-6 col-xs-6">  
  <?php   foreach($records as $row)
  { 
?>
 <div class="box box-primary">
<div class="box-header">
<h4><b> <?php echo $row->l_name;?></b></h4>
 <span class="input-group-btn">
<p>
<a data-toggle="modal" data-target="#loginModal" href=""><img src="<?php echo base_url(). "assets" ?> /images/edit.png" width="20px" height="20px"></a>
<a href="<?php echo base_url("admin/leads/deleteleads?ids=".$row->l_id); ?>"><img src="<?php echo base_url(). "assets" ?> /images/delete.png" width="30px" height="30px"></a>

</p>

<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="Login" aria-hidden="true">
 <div class="modal-dialog">
    <div class="modal-content">
 <div class="modal-header">
 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
   <span aria-hidden="true">&times;</span>
</button>
  <h3 class="modal-title" id="myModalLabel">Update Lead</h3>
 </div>

<div class="modal-body">

<?php echo form_open('admin/leads/updateleads?ids='.$row->l_id,['class'=>'form-horizontal panel' , 'method'=> 'POST']); ?>
  <div class="form-group">
 <label class="col-xs-3 control-label"><h4>Lead Name</h4></label>
<div class="col-xs-8">

  <input type="hidden" name="id" value="<?php echo $row->l_id ;?>"  class="form-control" />
   <input type="text" value="<?php echo $row->l_name ;?>" class="form-control" placeholder="Lead Name" name="l_name" />
<div class="form-group">
 <div class="col-xs-8 col-xs-offset-5">

<?php 
echo form_reset(['name'=>'cancel', 'data-dismiss'=>'modal'  , 'value'=>'Reset' , 'class'=>'btn btn-default']); 

?>
<?php 
echo form_submit(['name'=>'update' , 'value'=>'update' , 'class'=>'btn btn-primary']);
 ?>
 </div>
</div>
</form>
<div class="col-lg-6 col-xs-6">
 <div class="box box-primary">
<div class="box-header">
<h4><strong>Lead Value: </strong>Rs <?php echo $row->l_value;?></h4>
 <?php } ?> 
</section>



CONTROLLER:-


Code:
[color=#4f5155][size=small] public function editlead()
[/size][/color]
  {

  $this->load->model('admin/insert_leads');
$data['records']=$this->insert_leads->leadslist(); 

  $this->load->view("admin/vwLeads",$data);// 
}
 public function updateleads()
{
$id=$this->input->get('ids');
$this->load->model('admin/insert_leads');
$update = array( 'l_name' => $this->input->post('l_name'), );
$update["records"]=$this->insert_leads->updatelead($id); 

$this->form_validation->set_rules('l_name','Name','trim|required');
 if ($this->form_validation->run() == FALSE) {
$this->load->view('admin/vwLeadsdashboard');
        }
  else{
       $id = $this->input->post('l_id');
 $this->insert_leads->updatelead($id);
  redirect('admin/leads/leadsdashboard');
 }
  $this->load->view("admin/vwLeadsdashboard",$update); 
 redirect('admin/leads/leadsdashboard');
}
 public function deleteleads()
{
 $id=$this->input->get('ids');
$this->load->model('admin/insert_leads');
$update = array(  'l_id' => $this->input->post('l_id'), );
$update["records"]=$this->insert_leads->deletelead($id); 
redirect('admin/leads/leads/');
[color=#4f5155][size=small]  }[/size][/color]


MODEL:-



Code:
[color=#4f5155][size=small]<?php
[/size][/color]
class Insert_leads extends CI_Model{

function __construct()
{
parent::__construct();
}
function insertlead($data){
$query= $this->db->insert('leads', $data);
return $query;
}
function leadslist()
{
$this->db ->select('*')->from('leads');
$query = $this->db->get();    
return $query->result();
}
function getleadsid($id)
{
$this->db->select('*');
$this->db->from('leads');
$this->db->where('l_id', $id);  // Also mention table name here
$query = $this->db->get();    
 return $query->result();

}
function updatelead($id)
{
$update = array(  'l_name'  =>  $_POST['l_name'] ,);
$this->db->where('l_id', $id);
$this->db->update('leads', $update);
$query = $this->db->get();    
 return $query->result();
}
function deletelead($id)
{
$this->db->where('l_id', $id);
$this->db->delete('leads');
$query = $this->db->get();    
 return $query->result();
}

function todo()
{
$query= $this->db->insert('leads_activities', $data);
return $query;
}
}
[color=#4f5155][size=small]?>[/size][/color]
[/code]


thanks in advance 

please help me i am stuck..
Reply

#2
This post is way too long and unreadably formatted - learn to use bbcode to reduce the length, and reformat!
Reply

#3
(10-20-2016, 12:37 AM)ciadmin Wrote: This post is way too long and unreadably formatted - learn to use bbcode to reduce the length, and reformat!

I updated the Post is this much ok now?
Reply

#4
Please click on Full Edit or Reply to this topic to get a full page editor that allows images links and code.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#5
It is better, but indenting would improve readability - still can't tell what is supposed to happen.
Also, putting
Code:
...
around your code segments will shorten it, so readers don't bail because of the length ... see http://forum.codeigniter.com/misc.php?action=help&hid=7
Reply

#6
(10-20-2016, 06:38 AM)ciadmin Wrote: It is better, but indenting would improve readability - still can't tell what is supposed to happen.
Also, putting
Code:
...
around your code segments will shorten it, so readers don't bail because of the length ... see http://forum.codeigniter.com/misc.php?action=help&hid=7

is this ok now please help me.
Reply

#7
PHP Code:
function updatelead($id){
 
 $update = array(  'l_name'  =>  $_POST['l_name'] ,);
 
 $this->db->where('l_id'$id);
 
 $this->db->update('leads'$update);
 
 
  $query 
$this->db->get('leads');    // need to pass the table to the get method

 
 return $query->result();

A good decision is based on knowledge and not on numbers. - Plato

Reply

#8
(10-21-2016, 12:29 AM)salain Wrote:
PHP Code:
function updatelead($id){
 
 $update = array(  'l_name'  =>  $_POST['l_name'] ,);
 
 $this->db->where('l_id'$id);
 
 $this->db->update('leads'$update);
 
 
  $query 
$this->db->get('leads');    // need to pass the table to the get method

 
 return $query->result();


Thanku so much for helping me out.
Reply

#9
Your welcome.
A good decision is based on knowledge and not on numbers. - Plato

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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