Welcome Guest, Not a member yet? Register   Sign In
Apostrophes and Active Record
#1

[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);
#2

[eluser]Ryuuzaki92[/eluser]
what is the error message?
#3

[eluser]John Fuller[/eluser]
Happy birthday.

What errors do you receive?

Edit: Whoops, beat to the punch.
#4

[eluser]Developer13[/eluser]
Sorry - it's not really my birthday... just the first thing that came to mind Smile

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.
#5

[eluser]Ryuuzaki92[/eluser]
weird. what DB are you using?
#6

[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.
#7

[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).
#8

[eluser]Developer13[/eluser]
Ahh yes... that would be it. Thanks much, guys.
#9

[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.




Theme © iAndrew 2016 - Forum software by © MyBB