2

I've made a PHP script and a admin panel of it. But i have issue when inserting records into the DB. I'm using this code:

<input name="title" type="text" />

and to get it I use :

$code = $_REQUEST['title'];

But when i want to insert this text:

Un jour comme les autres, Gerry Lane et sa famille se retrouvent coincés dans un embouteillage monstre sur leur trajet quotidien. 

I fount that just :

Un jour comme les autres, Gerry Lane et sa famille se retrouvent coinc 

this is the code i use to insert into Db :

$q = "INSERT INTO `movies` (`code`) VALUES ('$code')";
$result = mysql_query($q) or die(mysql_error());

How can I fix it ?

checkopenport
  • 121
  • 1
  • 9
  • 2
    Please show us your query – Lance Sep 07 '13 at 15:28
  • What if your database table structure ? the field where you insert that text what is the type? – Prix Sep 07 '13 at 15:28
  • @Prix the structure is text – checkopenport Sep 07 '13 at 15:29
  • 1
    [This would probably help](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – JJJ Sep 07 '13 at 15:30
  • 1
    @checkopenport update your question with the portion of code used to insert the data into mysql. [You can use the **Edit link above** or clicking here to edit your question](http://stackoverflow.com/posts/18674854/edit) – Prix Sep 07 '13 at 15:30
  • Can you translate your error message to English? – Lance Sep 07 '13 at 15:35
  • @Lance I don't receive any error ! The text is just an example of text that i inputed into my db – checkopenport Sep 07 '13 at 15:37
  • @Juhana & OP: Yes, it's a character encoding problem; obviously it currently does not accept the accented e. See that link. – d'alar'cop Sep 07 '13 at 15:37
  • More likely than not, the answer to this question is correct. What's the 'code' column in your DB? – Lance Sep 07 '13 at 15:39
  • @checkopenport what is the result of `SHOW CREATE TABLE movies;` you can run that directly on MySQL or using phpMyAdmin. Update your question with the result, thx. – Prix Sep 07 '13 at 15:43
  • 1
    @Prix CREATE TABLE `movies` ( `code` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 – checkopenport Sep 07 '13 at 15:45
  • @checkopenport that's not a valid create table. – Prix Sep 07 '13 at 15:46
  • Ive just picked up COLUM That i needd – checkopenport Sep 07 '13 at 15:47
  • That's great but we need to see the entire structure to make sure its OK, answering your question based on assumptions of our part only takes our time without helping you or us. – Prix Sep 07 '13 at 15:48
  • CREATE TABLE `movies` ( `id` int(11) NOT NULL auto_increment, `titre` text NOT NULL, `description` mediumtext NOT NULL, `date` text NOT NULL, `qualite` text NOT NULL, `code` text NOT NULL, `pthumb` text NOT NULL, `gthumb` text NOT NULL, `youtube` text NOT NULL, `duree` text NOT NULL, `genre` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 – checkopenport Sep 07 '13 at 15:50
  • CREATE TABLE movies ( id int(11) NOT NULL auto_increment, titre text NOT NULL, description mediumtext NOT NULL, date text NOT NULL, qualite text NOT NULL, code text NOT NULL, pthumb text NOT NULL, gthumb text NOT NULL, youtube text NOT NULL, duree text NOT NULL, genre text NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 – checkopenport Sep 07 '13 at 15:52
  • @checkopenport this issue you're talking about does it only happen when you view the data on phpMyAdmin? or does it happen when using php and mysql to select the data from database – Prix Sep 07 '13 at 15:54
  • I fixed the problem ! ive tried to insert same text using phpMyadmin then i picked up the mysql query and put it into php file and it works fine thank you for your help @Prix I voted for you make an answer on this topic so i can be able to vote for you – checkopenport Sep 07 '13 at 16:01
  • So the issue was? What was the difference between the phpMyAdmin query and the one you're using? – Prix Sep 07 '13 at 16:05
  • Check your database structure and encoding. Especially check for database field length and check if 'mysql strict' is enabled. Can you post the result of this query "DESC movies;"? – GTodorov Sep 07 '13 at 16:44

1 Answers1

0

Problem might be that, in your table structure , the field name is restricted to for a length. e.g:- as i can geuss. field type might be varchar(70) or char(70). so it will accept only starting 70 character and save them in to that field.

so check that , and if it is not then tell us about structure of table .

please try this :

$code = utf8_encode($code);

before inserting into db.

developerCK
  • 4,418
  • 3
  • 16
  • 35
  • It's more likely that the input or output is cut at the accented character, but maybe it's just a coincidence. – JJJ Sep 07 '13 at 15:39
  • tell about data structure of table, end echo what you are getting in $code before inserting. – developerCK Sep 07 '13 at 15:41
  • 1
    He said his structure field type is text on the comments so this would not be the issue. – Prix Sep 07 '13 at 15:41
  • Data structure is text ! and when i echo it the full code appear well – checkopenport Sep 07 '13 at 15:43
  • tell us about db version, database engine, table collation etc. – developerCK Sep 07 '13 at 15:49
  • CREATE TABLE movies ( id int(11) NOT NULL auto_increment, titre text NOT NULL, description mediumtext NOT NULL, date text NOT NULL, qualite text NOT NULL, code text NOT NULL, pthumb text NOT NULL, gthumb text NOT NULL, youtube text NOT NULL, duree text NOT NULL, genre text NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 – checkopenport Sep 07 '13 at 15:53
  • please check the updated answer and let me know if it is useful to you – developerCK Sep 07 '13 at 16:42