Welcome Guest, Not a member yet? Register   Sign In
multilingual support for databases inserts
#1

[eluser]shujjat[/eluser]
\ well finally got something.

please visit this link http://www.tutorialjinni.com/2010/08/sto...g-php.html

i have a field in db as department_name in table departments

so, i write:

$department_name= $_POST['department_name']; $map = array(0x0, 0x2FFFF, 0, 0xFFFF);

$department_name=mb_decode_numericentity($department_name, $map, 'UTF-8');

$query=" INSERT INTO bf_departments (department_name,date_created,deleted) VALUES('$department_name',NOW(),'0')

;"
;
if i echo the query, i get:

INSERT INTO bf_departments (department_name,date_created,deleted) VALUES('شعبہ',NOW(),'0') ;

but when i do: $this->db->query($query); i get this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'شعبہ'','12','5','3',NOW(),'0')' at line 3 INSERT INTO bf_departments (department_name,date_created,deleted) VALUES('Ø

´Ø¹Ø¨Û'',NOW(),'0') ;

but if i open mysql and run it directly, no error is there and table is succesfully updated.

how can i correct it?
#2

[eluser]shujjat[/eluser]
need a fast reply here...
#3

[eluser]aquary[/eluser]
Something is wrong with you department_name value... I'm suspecting the ` character in the string...

Did you notice the query you echo and the query in the error are not the same?

Since you are not using CI's function for security, please try escape any string with mysql_real_escape_string before send it to the database.
#4

[eluser]meigwilym[/eluser]
With problems like this I get very specific with the SQL. Try
Code:
$query = "INSERT INTO bf_departments (department_name, date_created, deleted) VALUES('".$department_name."', NOW(), '0');
Subtle but oculd be important.

Mei
#5

[eluser]shujjat[/eluser]
thanks all....
i tried all you suggested and some modifications too... but still there.. same error... Sad
#6

[eluser]shujjat[/eluser]
waiting for suggestionsss
#7

[eluser]PhilTem[/eluser]
From the error you dumped in the OP it looks like the values you're trying to insert create apostrophes which screw the query.

Try

Code:
$query = "INSERT INTO `bf_departments` (`department_name`, `date_created`, `deleted`) VALUES('" . mysql_real_escape_string($department_name) . "', NOW(), '0');

On another hand: What is the char-set you're using for the connection (have a look at $db['default']['char_set'] = 'utf8'Wink and what's the char-set of your table? Might be a problem there.
#8

[eluser]shujjat[/eluser]
thanks... have checked the char set and it is utf8...
not solved yet Sad
#9

[eluser]shujjat[/eluser]
waiting....Sad
#10

[eluser]shujjat[/eluser]
waiting for some solution Sad




Theme © iAndrew 2016 - Forum software by © MyBB