1

here is my code i want to update the database field but facing error.i print the query data posting is correct but why ID=0 i have capital id in db table but why please answer me what is issue i want to update via ajax. 1UPDATE form SET st_name = 'hello', st_class = 'update', st_address = 'SystemConfig' WHERE ID = 0 because id is 0 that's why its not updating data but why.?

Here is my ajx function in view

   <script>
  $(document).ready(function() {

  $(".Update").fancybox({
    'transitionIn'  :   'fade',
    'transitionOut' :   'fade',
    'speedIn'       :   600, 
    'speedOut'      :   200, 
    'overlayShow'   :   false
});
var Id = $(this).attr("id");
var parent = $(this).parent();  
  $("#updateform").bind("submit", function() {
     $.ajax({
        type        : "POST",
        cache       : false,
        url     : "http://localhost/testproj/index.php/form/update",
        data        : $(this).serializeArray(),
            success:function(data){
                $.fancybox(data);
            }
    });


    return false;
  });

  });     

 **VIEW**



 </head>
<body>          




     <form id="Form" action="" method="post"
     name="Form" onsubmit="return submitForm();"  ;>
    <br></br>
    <table id = "fixedme" border ='0' cellpadding='0' cellspacing='0'>
    <tr>
    <td>Message:  </td>
<td><input id='Name' name='Name' type='text' size='20' maxlength='50'/></td>


                        <td>Action</td>
        <td><select name="action" id="action">
            <option value="">--Select--</option>
        <option value="insert">Insert</option>
       <option value="update">Update</option>
        <option value="delete">Delete</option></select></td>


                        <td>Action By</td>
            <td><select name="actionBy" id="actionBy">
            <option value="">--Select--</option>
        <option value="Transaction">Transaction</option>
        <option value="ManageOperation">Manage Operation</option>
        <option value="FeeRate">Fee Rate</option>
        <option value="SystemConfig">System Config</option>
        <option value="Compliance">Compliance</option>
        <option value="Usermanagement">User Management</option>
        <option value="OnlineSenderAdmin">Online Sender Admin</option>
        </select></td>
            </tr>
   <tr><td collspan='2'><input type="submit" name="submit" id="submit" value="submit" class="submit"/></td></tr></table>
        </form>
</div>


  <div style="display:none;" id = "updateDialog"  >
    <form id="updateform" action="" method="post">
    <p><h1 align="center">Update</h1></p>
        <p>
           <label>Message:</label>
           <input type="text" id="name" name="name" />
        </p>

        <p>
           <label>Action On:</label>
          <select name="action" id="action">
            <option value="">--Select--</option>
            <option value="insert">Insert</option>
            <option value="update">Update</option>
            <option value="delete">Delete</option></select>
        </p>
        <p>
           <label>ActionBy:</label>
           <select name="actionBy" id="actionBy">
    <option value="">--Select--</option>
    <option value="Transaction">Transaction</option>
    <option value="ManageOperation">Manage Operation</option>
    <option value="FeeRate">Fee Rate</option>
    <option value="SystemConfig">System Config</option>
    <option value="Compliance">Compliance</option>
    <option value="Usermanagement">User Management</option>
    <option value="OnlineSenderAdmin">Online Sender Admin</option>
    </select>
        </p>
        <p><input type="submit" name="save" 
             id="save" value="save" class="save"/>

        <input type="submit" name="Close" 
        id="Close" value="Close" class="submit"/>       
        </form>
  </div>


<div id="message">
<form id="myForm" action="" method="" name="myForm" class="myForm"><br></br>
<table id = "fixedme" border ='1' cellpadding='0' cellspacing='0'>
    <tr>
                        <th>ID:  </th>
                        <th>Message: </th>
                        <th>Action On:</th>
                        <th>ActionBy </th>
                        <th>Actions </th>

    </tr>
            <tbody>
            <?php
    if($result!="")
    {
    foreach($result as $rows){ ?>
    <tr id="ide"><td><span><?php echo $ID=$rows->ID;?></span></td> 
    <td><span><?php echo $name=$rows->st_name;?></span></td>
    <td><span><?php  echo $action=$rows->st_address; ?></span></td>
    <td><span><?php echo  $actionby=$rows->st_class; ?> </span></td>
    <td><a href="#"  class="delete" id="<?php echo $ID=$rows->ID;?>" 
        name="delete" >Delete</a>
    <a href="#updateDialog"  class="Update" id="<?php echo $ID=$rows->ID ;?>" 
    name="Update">Update</a>
    </td></tr>
            <?php }}?>

            </tbody>
            </table>
            </form>
            </div>
            </div>
        </div>
</body>
 </html>



 **MODEL**

     public function submit_updated_data($id,$data) 
        {
            $this->load->database();
            $this->db->where('ID', $id);
            $query2 =$this->db->update( 'form', $data);

        }



**CONTROLLER**


  public function update()
 {
        $id=$this->input->post('ID');
        $name=$this->input->post('name');
        $action= $this->input->post('action');  
        $actionBy = $this->input->post('actionBy'); 
        $data = array(

                    'st_name' => $name,
                    'st_class' =>$action,
'st_address'=>$actionBy                             
                    );
    $this->form_model->submit_updated_data($id,$data);
                            $this->index();

}

1UPDATE `form` SET `st_name` = 'hello', `st_class` = 'update', `st_address` = 'SystemConfig' WHERE `ID` = 0
4
  • Model and controller are also in above code please need answer. Commented Dec 17, 2012 at 15:49
  • how to pass id ?but it shows id is 0 why ? if i hard code the id in model query then it updates the data of just that id . is it problem in query or ajax function ? Commented Dec 17, 2012 at 15:51
  • here is query result (1UPDATE form SET st_name = 'hello', st_class = 'update', st_address = 'SystemConfig' WHERE ID = 0 ) Commented Dec 17, 2012 at 17:21
  • check your input data: print_r($this->input->post(null)) Commented Dec 18, 2012 at 9:44

1 Answer 1

1

I think it's because you aren't submitting an ID for the record to update in the $_POST array.

All the data being submitted is an array built from your form inputs, but you don't have one for 'id'...so:

$id=$this->input->post('ID');

...isn't getting anything from the form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.