Reputation: 942
I have insert to columns with single quotes. As $this->db->query
already takes care of all the special character. But my problem is i to insert data like ganesh's when the insertion takes place, only ganesh is inserted; data after the single quotes are missing. So i started using $this->db->escape
but this adds single quotes to my data which is not required how to prevent this
my code
$sql="insert into tablename (list_name,list_address) values(?,?)"
$res=this->db-query($sql,array($name,$add));
MY mistake was in front end. Not back end. I will delete the question.
Upvotes: 4
Views: 11004
Reputation: 5050
If you want to save the data with the single quote you will need to add slashes to the data before saving it to the database like this:
$sql="insert into tablename (list_name,list_address) values(?,?)";
$res=this->db-query($sql,array(addslashes($name), $add));
then save that into your database, after doing this you will most likely need to use stripslashes()
to remove the slashes from the data before you output it to the browser.
Upvotes: 2
Reputation: 16062
In cases of complex queries i find it easier to just send raw query like this :
$query = "your query";
$result = $this->db->query($query);
Don't forget to escape variables before inserting them to the query like this :
$var = $this->db->escape($var);
Upvotes: 5