Debbie-Leigh Posted November 5, 2007 Share Posted November 5, 2007 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: ------ 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 Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/ Share on other sites More sharing options...
trq Posted November 5, 2007 Share Posted November 5, 2007 Is that data meant to be one long string or seperate lines? Are you running the data through trim to remove any unwanted whitespace? Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/#findComment-385245 Share on other sites More sharing options...
Debbie-Leigh Posted November 5, 2007 Author Share Posted November 5, 2007 Hi Thorpe, It is one set of data, but each line shown above is separated by a new line character, which is why it shows up like that in the view source window that I copied it from. Debbie Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/#findComment-385258 Share on other sites More sharing options...
MadTechie Posted November 5, 2007 Share Posted November 5, 2007 can you echo the SQL query and post that, it may be an idea to do a select from the existing record and post that.. it may be come clear! Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/#findComment-385261 Share on other sites More sharing options...
Debbie-Leigh Posted November 6, 2007 Author Share Posted November 6, 2007 Hi MadTechie, The update query is: 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: $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; 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 Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/#findComment-385284 Share on other sites More sharing options...
Debbie-Leigh Posted November 6, 2007 Author Share Posted November 6, 2007 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: if (preg_replace('/[\r\n]+/', "", $rsLicDtls["contents"]) == preg_replace('/[\r\n]+/', "", $pstLicCode)): Debbie Quote Link to comment https://forums.phpfreaks.com/topic/76114-why-does-my-page-save-a-textarea-wrongly/#findComment-385304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.