EllisLab text mark
Advanced Search
     
Unknown column ‘Free’ in ‘field list’
Posted: 15 July 2011 03:07 AM   [ Ignore ]
Avatar
Joined: 2010-09-26
10 posts

I am encountering a strange error which I am not able to replicate with earlier version of Codeigniter (1.7)

The error I get is

A Database Error Occurred

Error Number
1054

Unknown column 
'Free' in 'field list'

INSERT INTO `devices` (`deviceIdentifier`, `installType`) VALUES (351863048175265Free)

FilenameD:\wamp\www\Everythingelse\sieveSMS\system\database\DB_driver.php

Line Number
330 


My Controller code is as follows

$deviceID=$xmlString->deviceID;
            
$appType=$xmlString->appType;
            
$data = array(
                
'deviceIdentifier' => $deviceID,
                
'installType'=>$appType
            
);
            
$this->device_model->insert_new_device($data); 

My model code is as follows

<?php

class device_model extends CI_Model
{
    
function insert_new_device($lData)
    
{
        $this
->db->insert('devices'$lData);
        return 
$this->db->insert_id();
    
}
}
?> 

The two variables ‘$deviceID’ and ‘$appType’ have valid alphanumeric values.The columns ‘deviceIdentifier’ and ‘installType’ are varchar columns in table ‘devices’

Has anyone encountered this error? when I add quotes around the variables ‘$deviceID’ and ‘$appType’, it works, but the value in the table also has the quotes.Do we need to process text data before inserting in the MySQL table via active record?

 
Posted: 18 July 2011 08:57 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-02
134 posts

Put the code below in your controller:

var_dump($appType); 

and what is in it?

 
Posted: 18 July 2011 09:43 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2006-12-04
515 posts

I would think this should fix it:

$deviceID = (int) $xmlString->deviceID;
$appType = (string) $xmlString->appType
 Signature 

————————
Eric Barnes | Twitter
————————

 
Posted: 19 July 2011 10:27 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-09-26
10 posts

var_dump($appType);  echoes the following

object(SimpleXMLElement)#19 (1) { [0]=> string(4) “Free” }

As suggested by Eric Barnes casting worked!