1

There are posts here already for this issue but I still don't get the database to update. Ajax sends me a 200 OK but as said no db update: (the $platform->id is not the issue, foreach is set). Thank you for help!

Jquery

$('#button_<?php echo $platform->id; ?>').click(function(event) {
    event.preventDefault();
    var platform_id = <?php echo $platform->id; ?>;
        $.ajax({
            type: "POST",
            url: "<?php echo site_url('home/select_job'); ?>",
            data: {id : platform_id},
            success: function(){ alert("success"); },
        });

Controller

$platform_id = $this->input->post('platform_id');
$user_id = $this->session->userdata('id');
$this->users_model->job_selection($user_id, $platform_id);

Model

public function job_selection($user_id, $platform_id){
    $this->db->set('user_id', $user_id);
    $this->db->set('status', 2);
    $this->db->set('select_company', 1);
    $this->db->where('id', $platform_id);
    $this->db->update('companies');
}

1 Answer 1

3

You are making mistake to getting the platform_id it will be id because you set the name id into your ajax call try this into your controller

$platform_id = $_POST['id'];
$user_id = $this->session->userdata('id');
$this->users_model->job_selection($user_id, $platform_id);

Try this hope it will solve problem.

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

1 Comment

Good catch. I try to always leave field names the same...db, form, variable name, JSON/Array key, etc...changing them around from user_id to id, etc just introduces opportunities to screw up.

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.