Saving PHP variable to MySQL INT is always 0
<p>I am having a problem passing a variable to be saved as INT in MySQL.  The closest thing I could find to my issue is <a href="https://stackoverflow.com/questions/10255724/incorrect-integer-2147483647-is-inserted-into-mysql">this question</a> but I have already verified that I am not using single and double quotes.  When I <code>print_r($this-&gt;session-&gt;userdata('subdomain'))</code> I see the correct subdomain id on my screen (in this case 10), but when I try passing this using $params it always save subdomain_id as 0 and I can not figure out why.</p>

<p>Here is Project_assignees_model:</p>

<pre><code>function add_prefix_project_assignees($params)
{
    $this-&gt;db-&gt;insert('prefix_project_assignees',$params);
    return $this-&gt;db-&gt;insert_id();
}
</code></pre>

<p>Here is my Project controller (Specifically it is the <code>$assignees</code> array):</p>

<pre><code>function edit($entry_id)
    {   
        $this-&gt;load-&gt;library('form_validation');

        $this-&gt;form_validation-&gt;set_rules('client_id','Client Id','required|integer');
        $this-&gt;form_validation-&gt;set_rules('title','Project Title','required|max_length[255]');
        $this-&gt;form_validation-&gt;set_rules('project_status','Project Status','required');
        $this-&gt;form_validation-&gt;set_rules('project_details','Project Details','required');
        $this-&gt;form_validation-&gt;set_rules('project_estimated_hours','Project Estimated Hours','required|max_length[255]');
        $this-&gt;form_validation-&gt;set_rules('end','Project Deadline','required');

        if($this-&gt;form_validation-&gt;run())     
        {   
            date_default_timezone_set("America/New_York");
            $date = date("Y-m-d h:i:sa");

            $params = array(
                'subdomain_id' =&gt; $this-&gt;session-&gt;userdata('subdomain'),
                'client_id' =&gt; $this-&gt;input-&gt;post('client_id'),
                'title' =&gt; $this-&gt;input-&gt;post('title'),
                'project_status' =&gt; $this-&gt;input-&gt;post('project_status'),
                'project_details' =&gt; $this-&gt;input-&gt;post('project_details'),
                'project_last_updated' =&gt; $date,
                'project_estimated_hours' =&gt; $this-&gt;input-&gt;post('project_estimated_hours'),
                'start' =&gt; $this-&gt;input-&gt;post('start'),
                'end' =&gt; $this-&gt;input-&gt;post('end'),
                'owner_id' =&gt; get_current_user_id(),
            );

            $prefix_projects_id = $this-&gt;Project_model-&gt;update_prefix_projects($entry_id,$params);

            $assignees = array(
                'subdomain_id' =&gt; $this-&gt;session-&gt;userdata('subdomain'),
                'project_id' =&gt; $entry_id,
                'user_id' =&gt; $this-&gt;input-&gt;post('assignee'),
            );

            $this-&gt;load-&gt;model('Project_assignee_model');

            $insertAssignees = array();
            for ($i = 0; $i &lt; count($assignees['user_id']); $i++)
            {
                //Get user_id from ID
                $userID = $assignees['user_id'][$i];

                $insertAssignees[$i] = array('project_id' =&gt; $entry_id, 'user_id' =&gt; $assignees['user_id'][$i]); // $insert is ready for insert_batch

                $prefix_assignees = $this-&gt;Project_assignee_model-&gt;add_prefix_project_assignees($insertAssignees[$i]);
            }

            //redirect('project/index');
        }
        else
        {   
            $this-&gt;load-&gt;model('Client_model');
            $data['prefix_clients'] = $this-&gt;Client_model-&gt;get_all_prefix_clients();
            $data['prefix_projects'] = $this-&gt;Project_model-&gt;get_prefix_projects($entry_id);
            $data['prefix_users'] = $this-&gt;aauth-&gt;list_users();
            $this-&gt;load-&gt;model('Project_assignee_model');
            $data['prefix_assignees'] = $this-&gt;Project_assignee_model-&gt;get_prefix_project_assignees($entry_id);
            $this-&gt;load-&gt;view('project/edit',$data);
        }
    }
</code></pre>

<p><a href="https://i.stack.imgur.com/95XP7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/95XP7.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/BivJa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BivJa.png" alt="enter image description here"></a></p>

<p><strong>Why does <code>print_r</code> show the correct subdomain_id but when it is saved to database it saves as 0?</strong></p>

<p>*******UPDATE*******</p>

<p>Just for reference, this works:</p>

<pre><code>$assignees = array(
       'subdomain_id' =&gt; 10,
       'project_id' =&gt; $entry_id,
       'user_id' =&gt; $this-&gt;input-&gt;post('assignee'),
);
</code></pre>

<p>But this does not (Even though printing the userdata for subdomain gives me 10):</p>

<pre><code>$assignees = array(
       'subdomain_id' =&gt; $this-&gt;session-&gt;userdata('subdomain'),
       'project_id' =&gt; $entry_id,
       'user_id' =&gt; $this-&gt;input-&gt;post('assignee'),
);
</code></pre>