Jump to content

Why does my page save a textarea wrongly?


Debbie-Leigh

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.