#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Bristol, England
    Posts
    114
    Rep Power
    17

    Why does my page save a textarea wrongly?


    Hi,

    I have a PHP page (page 1) with a textarea on it, which is saved to a database. I also have a validation page (page 2) that has the same value as the textarea posted to it, which it needs to compare with the database value.

    Unfortunately, when I save the value using page 1, it doesn't match the value posted to page 2. The curious thing is that when I save the same value in the same field using phpMyAdmin, the match works perfectly.

    So, can anyone tell me what difference there could be in saving a textarea on a PHP page vs saving a textarea in phpMyAdmin? I've tried using the form tag with and without enctype="multipart/form-data", but neither works.

    The data I'm trying to save is:
    Code:
    ------ LICENSE FILE DATA -------
    U5U65106eL4dZIJzjqbzpuxB7/L7KC/Z
    1QlZQyEkfcBYLH2HKRzfvGlnRWJ+Qjyb
    fu5CfVfTadaxnNGVdnzsSNsi8IzHVQDO
    P/B7H52KtI1i9Jcf3x6IHbD73H9Rld2X
    vJqBBo+zlJszygJsxgnVs0FkQ2s4s6hO
    852AnRaQ5QT/EE58OOECWMm6SJzPQ6L9
    5h3+GN8UDelBFyK6oVkr/cTnM5emrIST
    H0mqTEI1Q3My2dBIEY7RltSpfcDiXeVZ
    /s4BVsoKSb5m8sDJtvSUbhga7S1liGuk
    cWJHDhmxhw/eQPMbYADSde+LaV/aZSo7
    03cVnM96mxvqL0ZybttJRsPE+JFhE+wS
    4BekkyHlEZHW2B0D/IlTRg4g52hTeizY
    eU7SQUDqhTm1yhOXHo0ftnIYjZYkc3ph
    w5jN/85bKDrvzjxjO0b29F3M4+ZvS8/5
    6x0D52pPUwuf0jkv9yKpPCmkzo/XGi+t
    LotKoEF9zaNM/IIaJrzyUECQXbuNZAXo
    A+qORwyzVGQxEJI5MTe8hUHYrtmGCOSQ
    rMjzxEKtzHrL9vX9c+Q7UaM7TNcDYJcy
    skvmZf6WAmtqyKZxRkaoLTfGXe82mlb6
    QTPFrixn1gBBx7eQtZXS7I1AOr97jKYf
    u7xy6V11biKPe7z6TdOFfUn2BxQ5T1Nv
    lVKTS7ff8mVgdYtC5thyA7rkivIb15Ku
    kMYDj9PciDtmNWp4uA2NL1XLFB9c4qgL
    hhRKRhYFK70n4CyupfSLSDyDRksHdPlg
    lhLBT5EJ5jzhCZmUdZ123d2t
    --------------------------------
    And I'm using a normal SQL update statement to save it.

    Debbie
    QuicknEasySalesPro.com
    - your quick and easy, yet powerful solution for managing your
    membership site sales, downloads and affiliates.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    In a constant state of turmoil
    Posts
    855
    Rep Power
    86
    How are you comparing the database entry to what's entered into the text field? Have you echoed both to the screen on page 2 to try and visually detect differences? My first guess would be that magic_quotes is on and there are some escaping slashes in the posted value from page 1 that make it different from the database value.... Obviously just a guess though.
    - Butcher -
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    22
    In addition to the magic quotes, there are probably the '\n' or newline characters?

    Can you post the contents of your DB as well once it is saved?
    Last edited by sp00nix; November 5th, 2007 at 09:38 PM.
    To err is human, to set_error_handler(), is divine...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Bristol, England
    Posts
    114
    Rep Power
    17
    Hi butcher,

    The update query is:
    Code:
    UPDATE licence
    SET contents = '------ LICENSE FILE DATA -------
    U5U65106eL4dZIJzjqbzpuxB7/L7KC/Z
    1QlZQyEkfcBYLH2HKRzfvGlnRWJ+Qjyb
    fu5CfVfTadaxnNGVdnzsSNsi8IzHVQDO
    P/B7H52KtI1i9Jcf3x6IHbD73H9Rld2X
    vJqBBo+zlJszygJsxgnVs0FkQ2s4s6hO
    852AnRaQ5QT/EE58OOECWMm6SJzPQ6L9
    5h3+GN8UDelBFyK6oVkr/cTnM5emrIST
    H0mqTEI1Q3My2dBIEY7RltSpfcDiXeVZ
    /s4BVsoKSb5m8sDJtvSUbhga7S1liGuk
    cWJHDhmxhw/eQPMbYADSde+LaV/aZSo7
    03cVnM96mxvqL0ZybttJRsPE+JFhE+wS
    4BekkyHlEZHW2B0D/IlTRg4g52hTeizY
    eU7SQUDqhTm1yhOXHo0ftnIYjZYkc3ph
    w5jN/85bKDrvzjxjO0b29F3M4+ZvS8/5
    6x0D52pPUwuf0jkv9yKpPCmkzo/XGi+t
    LotKoEF9zaNM/IIaJrzyUECQXbuNZAXo
    A+qORwyzVGQxEJI5MTe8hUHYrtmGCOSQ
    rMjzxEKtzHrL9vX9c+Q7UaM7TNcDYJcy
    skvmZf6WAmtqyKZxRkaoLTfGXe82mlb6
    QTPFrixn1gBBx7eQtZXS7I1AOr97jKYf
    u7xy6V11biKPe7z6TdOFfUn2BxQ5T1Nv
    lVKTS7ff8mVgdYtC5thyA7rkivIb15Ku
    kMYDj9PciDtmNWp4uA2NL1XLFB9c4qgL
    hhRKRhYFK70n4CyupfSLSDyDRksHdPlg
    lhLBT5EJ5jzhCZmUdZ123d2t
    --------------------------------'
    WHERE licence_id = '2'
    and the comparing code is:
    Code:
    $strQuery = "SELECT contents
                   FROM licence
                  WHERE licence_id = '$pstId'
                ";
    $qsLicDtls = $objDbConn->runQuery($strQuery, __LINE__, TRUE);
    if  ($qsLicDtls):
    	if  ($objDbConn->numRows() > 0):
    		$rsLicDtls = $objDbConn->fetchArray();
    		if  (trim($rsLicDtls["contents"], CR . NL) == trim($pstLicCode, CR . NL)):
    			echo "1";
    		else:
    			echo "0";
    		endif;
    	else:
    		echo "0";
    	endif;
    else:
    	echo "0";
    endif;
    magic_quotes_gpc is on and magic_quotes_runtime is off, but the posted value in page is visually exactly the same as the one shown here.

    From my testing, the problem lies with the update query rather than the comparison code, because saving the same query in phpMyAdmin causes the comparison code to work, whereas saving it with the update query causes it to fail. Looking at the field value in phpMyAdmin, it is visually exactly the same after saving it in both ways.

    Debbie
    QuicknEasySalesPro.com
    - your quick and easy, yet powerful solution for managing your
    membership site sales, downloads and affiliates.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Bristol, England
    Posts
    114
    Rep Power
    17
    Hi,

    I've been given the solution now, so I thought I'd share it in case someone else finds themself in a similar pickle.

    The problem turns out to be a difference in line endings (\r and \n) between what is saved by phpMyAdmin and what is saved by my page. As you can see, there are line endings embedded within the value, not just at either end.

    I used the following code for the if test and everything works fine now:
    Code:
    if (preg_replace('/[\r\n]+/', "", $rsLicDtls["contents"]) == preg_replace('/[\r\n]+/', "", $pstLicCode)):
    Debbie

    Comments on this post

    • sp00nix agrees
    QuicknEasySalesPro.com
    - your quick and easy, yet powerful solution for managing your
    membership site sales, downloads and affiliates.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    140
    Rep Power
    22
    That's just what I suspected!
    To err is human, to set_error_handler(), is divine...

IMN logo majestic logo threadwatch logo seochat tools logo