very long text not inserted in database

Discussion in 'PHP' started by r1919, Feb 15, 2009.

  1. #1
    Hi,

    I want to insert/update a very long text into database but it doesn't work.
    I use longtext in database.
    it works for shorter text.

    when i update with $_post['textarea'] the value remain the same (empty or previous shorter text added before).

    it also work on my pc but not on the server. i imported there my database and the same thing.


    anyone have any idea?
     
    r1919, Feb 15, 2009 IP
  2. fdoze

    fdoze Peon

    Messages:
    205
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Show us your php code.

    Also the Database structure...


    So I can help you.
     
    fdoze, Feb 15, 2009 IP
  3. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $val = stripslashes($_POST['text_atricol']);
    if(get_magic_quotes_gpc()) {
    $val = stripslashes($_POST['text_atricol']);
    }
    $val = str_replace('\\', '\', $val);
    $val = mysql_real_escape_string($val);

    $q = "UPDATE
    articole
    SET
    articol_html = '$val'
    WHERE id = $_POST[id]";
    $sql->query($q, SQL_NONE);



    Table Information

    Storage engine: MyISAM
    Charset: latin1
    Rows: 2
    Size: 240 B
    Overhead: 0 B
    Auto Increment: 114

    let me know if you need more info
     
    r1919, Feb 16, 2009 IP
  4. krdzal

    krdzal Peon

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    mysql_query("UPDATE ......) or die(mysql_error();

    try that and maybe you will find easier what is the problem. It should tell you. I think the size of the field is not declared right so there is not enough space for the text. Maybe some versions diferences on the DB server or something like that. Hope this helps
     
    krdzal, Feb 16, 2009 IP
  5. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    this is the 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 'apprécier à l'aune des ambitions qu'elle prétend poursuivre' at line 4

    the apprécier à l'aune des ambitions qu'elle prétend poursuivre' is a part of text.

    i cannot use htmlspecialchars because a use an text editor.
     
    r1919, Feb 16, 2009 IP
  6. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    any ideas?
     
    r1919, Feb 16, 2009 IP
  7. MC_delta_T

    MC_delta_T Member

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #7
    i think your db charset is not right. try iconv to change variables charset to your dbs charset. for example; UTF-8 to ISO-8859-1
    $variable = iconv("UTF-8","ISO-8859-1//TRANSLIT",$variable);
    PHP:
     
    MC_delta_T, Feb 16, 2009 IP
  8. rcadble

    rcadble Peon

    Messages:
    109
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can try doing a BLOB instead of LONGTEXT in the database structure.
     
    rcadble, Feb 16, 2009 IP
  9. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    mysql_real_escape_string should take care of any issues with characters. I agree with using a BLOB instead.

    But, could you
    var_dump($q);
    PHP:
    before you insert, and post what it says?
     
    Altari, Feb 16, 2009 IP
  10. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    it says NULL
     
    r1919, Feb 16, 2009 IP
  11. Altari

    Altari Peon

    Messages:
    188
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #11
    It says null even after the form is submitted?

    $q = "UPDATE
    articole
    SET
    articol_html = '$val'
    WHERE id = $_POST[id]";
    
    var_dump($q);
    
    $sql->query($q, SQL_NONE);
    PHP:
     
    Altari, Feb 17, 2009 IP
  12. r1919

    r1919 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    seams that it's working now.

    this is the code:

    if(get_magic_quotes_gpc()) {
    $val = stripslashes($_POST['text_atricol']);
    }
    	$val = str_replace('\\', '\', $val);
    	$val = mysql_real_escape_string($val);
    	$val = iconv("UTF-8","ISO-8859-1//TRANSLIT", $val);
    	
    mysql_query("UPDATE
    articole
    SET
    articol_html = '$val'
    WHERE id = '$_POST[id]'") or die(mysql_error());
    PHP:
    thanks a lot for your effort.
     
    r1919, Feb 17, 2009 IP