2

I have two tables one is 'student' another is 'status'.The student table has a foreign key status_status_id. I want to update this status_status_field. In my view the all the status (junior, senior, fresher, sophomore) from the status are shown in a drop down menu.

I want to update the status_status_id (initially it has the value 0) field of student table by taking inputs from this drop down. And to update i also need the id of a particular student. The problem is the field status_status_id is not updating. The following error is showing-

A Database Error Occurred

Error Number: 1054

Unknown column 'Array' in 'where clause'

UPDATE `student` SET `0` = '' WHERE `id` = Array

Filename: Z:\www\CI\system\database\DB_driver.php

Line Number: 330

my controller

public function update()
{
    $id = $this->input->post('id');
    $data = array(
        'status_status_id' => $this->input->post('status_status_id'),
    );
    $this->status_model->update($data, $id);
}

my model

public function update($data, $id)
{
    $this->db->where('id', $id);
    $this->db->update('student', $data);
}

View for adding a status

<?php echo form_open('status_controller/update'); 
    $r = $info[0]->id;
    $data = array (
        'id' => $r,
        'status_status_id' => set_value('status_status_id')
    );
    ?>
    <p><?php echo form_input($data); ?>
        <p><select name ='status_status_id'>
        <?php echo form_error('status_status_id'); ?>
        <br /><?php
        $getType = mysql_query("SELECT status_id, status FROM status ORDER BY status_id");
        while ($type = mysql_fetch_object($getType)) {
            echo "<option value=\"{$type->status_id}\">{$type->status} </option>", set_value('status_status_id');
        }
        ?>
    </p>
    <p><?php echo form_submit('submit', 'Update Status'); ?></p>
<?php echo form_close(); ?>
0

1 Answer 1

3

I see the view having few errors. I'll just rewrite it with comments, it should then work.

Notice that you should move all database queries outside the view, and of course add validation. I am not sure if ID is actually an integer.

// I suppose this gives us a single ID, not an array of IDs or something else
$r = $info[0]->id;

// put the ID in a hidden field, so POST sends an "id" variable
$hidden_fields = array('id' => $r);

// add the hidden fields directly in form_open()
echo form_open('status_controller/update', '', $hidden_fields); 

// making $getType = mysql_query("SELECT status_id, status FROM status ORDER BY status_id"); in an active record way
$this->db->select('status_id, status');
$this->db->order_by('status_id', 'asc');
$query = $this->db->get('status');

// loop to make an array of the statuses to insert in form_dropdown() array('value' => 'display')
$statuses = array();
foreach ($query->result() as $row)
{
    $statuses[$row->status_id] = $row->status;
}

// you would probably be able to get the current status_status_id
// I will suppose that $info[0]->status_status_id holds that data
echo form_dropdown('status_status_id', $statuses, set_value('status_status_id', $info[0]->status_status_id));
echo form_error('status_status_id');
echo form_submit( 'submit', 'Update Status');
echo form_close();

The controller:

function update(){
    // again, this is suspicious from your example, check if it's not an Array
    $id = $this->input->post('id');
    $data = array(
        'status_status_id' => $this->input->post('status_status_id'),
    );

    $this->status_model->update($data, $id);
}

The model:

function update($data, $id){
    $this->db->where('id', $id);
    $this->db->update('student', $data);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.