![]() |
Problem in single quote - 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: Problem in single quote (/showthread.php?tid=38303) |
Problem in single quote - El Forum - 02-04-2011 [eluser]Tamilmani[/eluser] Hi All, I am using SQL database in my back end application. I need to allow the single quote(') values into the database.Any one suggest me how to fix this issue in Code igniter. For Example: Mc'Donald - I need to allow this value into database. Thanks Tamilmani Mohan Problem in single quote - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] http://php.net/manual/en/function.addslashes.php http://www.php.net/manual/en/function.stripslashes.php Code: $add = "Mc’Donald - I need to allow this value into database."; Problem in single quote - El Forum - 02-04-2011 [eluser]Tamilmani[/eluser] I have tried those things For Example: $name = "Mc'Donald"; $slashName = addslashes($t); // output- 'Mc\'Donald' insert into user(user_name)values('$slashName'); when i tried to run the above query. Getting below error message. Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'Donald'. Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark after the character string ') '. Problem in single quote - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] Can you copy your controller/model where are you processing this $name and the query? Problem in single quote - El Forum - 02-04-2011 [eluser]Tamilmani[/eluser] My Controller Code function addUser() { $rules['username']="required"; $rules['password']="required"; $rules['fisrtname']=""; $rules['lastname']=""; $rules['address']="" $this->validation->set_rules($rules); $fields['username']="UserName"; $fields['password']="Password"; $fields['fisrtname']=""; $fields['lastname']=""; $fields['address']="" $this->validation->set_rules($fields); if($this->valdiation->run()== FALSE) { } else { $firstname= addslashes($this->validation->firstname); $this->User_Model->addnewUser($this->validation->username,$this->validation->password,$firstname,$this->validation->lastname,$this->validation->address); } } Model Code function addnewUser($username,$password,$firstname,$lastname,$address) { $this->db->query("insert into users(UserName,Password,FirstName,LastName,Address)values('$username','$password','$firstname','$lastname','$address')"); return $this->db->insert_id(); } Problem in single quote - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] Why don't you use Active Record? It will be easier and class Validation was deprecated on CI 2.0. What version of CI are you using? Well assuming that he info you are passing to the model is right, you can try the next: Code: function addnewUser($username, $password, $firstname, $lastname, $address) And remove $firstname= addslashes($this->validation->firstname); Problem in single quote - El Forum - 02-04-2011 [eluser]Tamilmani[/eluser] I am using older version of codeigniter 1.7. Is it any alternate way to do addslashes. For example If we set in rules then no need to write the addslashes in each model function. like $rules['firstname']="required|addslashes" is it possible? Problem in single quote - El Forum - 02-04-2011 [eluser]Isern Palaus[/eluser] Did u tried what I said? The model part |