CodeIgniter Forums
Insert into database error with CI 1.6.1 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Insert into database error with CI 1.6.1 (/showthread.php?tid=8135)



Insert into database error with CI 1.6.1 - El Forum - 05-06-2008

[eluser]123XD[/eluser]
Hi,

I am just update CI from 1.54 to 1.61, and the database insertion not working,
it works for 1.54, I am using MSSQL 2005.

The view page is a simple form, and in the controller I just simply get 3 post variables and in controller i am using

Code:
$data = array
    (
      'Firstname' => $firstname, //$firstname data retrieve from form
      'Lastname' => $lastname,
      'Email' => $email
    );
    $this->db->insert('Demo', $data);

this brings me a error as followd
and the error as followed

Code:
INSERT INTO "Demo" ("Firstname", "Lastname", "Email") VALUES ('User', 'Tmp', '[email protected]')

I paste it into MSSQL 'new query' and execute it, it works. Anyone have any ideas??
I think it's the problem with the double quotes around the table name, but i don't know how to fix it.

Cheers,


Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]123XD[/eluser]
well, maybe there are some bugs for 1.6.1

I just tried CI 1.6.0, everything works fine.


Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]gtech[/eluser]
I use 1.6.1 and have no problems with inserts.. What is the actual error message? and what driver are you using?
Code:
$dbRet = $this->db->insert($table, $data_array);
    if (!$dbRet) {
      // will only get this far if db_debug is false.
      // otherwise it will be displayed on the browser automatically.
      echo $this->db->_error_message();
      echo $this->db->_error_number();
    }



Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]123XD[/eluser]
Quote:An Error Was Encountered
Error Number:

INSERT INTO "Demo" ("Firstname", "Lastname", "Email") VALUES ('User', 'Tmp', '[email protected]')

that's all i got from the error, it does not have a error number,
driver?? mssql driver


Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]gtech[/eluser]
sincere apologies I misread the database you are using, I have not used MSSQL before so may be very little help (I asked about the driver in case you may of accidentally used the wrong one in the database config).

[edit] found problem below [/edit]


Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]gtech[/eluser]
ooo.. this thread might help it highlights the double quote problem.

[url="http://ellislab.com/forums/viewthread/73664/"]http://ellislab.com/forums/viewthread/73664/[/url]
and
[url="http://ellislab.com/forums/viewthread/71558/#353513"]HERE IS THE FIX[/url]


Insert into database error with CI 1.6.1 - El Forum - 05-07-2008

[eluser]123XD[/eluser]
cool~~

Thanks for that. Smile