Apostrophes and Active Record |
[eluser]Developer13[/eluser]
Why would I receive errors when inserting data that contains apostrophes when using CI's active record class to build my queries? For example: $data = array("fieldname"=>"it's my birthday"); $this->db->insert("tablename", $data);
[eluser]John Fuller[/eluser]
Happy birthday. What errors do you receive? Edit: Whoops, beat to the punch.
[eluser]Developer13[/eluser]
Sorry - it's not really my birthday... just the first thing that came to mind ![]() Error is 1064. It errors out because it executes the following: INSERT INTO tablename (fieldname) VALUES ('it's my birthday') The apostrophe is not being escaped.
[eluser]champs[/eluser]
Something tells me this won't be solved unless you disable magic quotes. Apparently Rick thinks addslashes() is good enough (it's not!), since ExpressionEngine does the same stupid thing, too.
[eluser]Michael Wales[/eluser]
Odd... I've never had this issue (of course, I also think my magic quotes are off - as they should be).
[eluser]Developer13[/eluser]
Ahh yes... that would be it. Thanks much, guys.
[eluser]Ryan Pharis[/eluser]
I'm having the same problem as the original poster. My magic quotes are off, running php 5.2 and codeigniter 1.6.1. I get the same 1064 error message when entering a string with an apostrophe. Any ideas why it's not getting escaped? I'm using active record to insert the data also. Thanks for the help! EDIT: Nevermind, I was using $_POST['name_of_my_text_field'] instead of $this->input->post('name_of_my_text_field'). Once I made the switch, I had no problems with inserting apostrophes into the db. |
Welcome Guest, Not a member yet? Register Sign In |