Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2007, 10:02 PM   PM User | #1
Debbie-Leigh
New Coder

 
Join Date: Jul 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Debbie-Leigh is an unknown quantity at this point
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.
Debbie-Leigh is offline   Reply With Quote
Old 11-05-2007, 10:05 PM   PM User | #2
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
You're going to need to show the code that saves, and the code that compares.
aedrin is offline   Reply With Quote
Old 11-05-2007, 11:23 PM   PM User | #3
Debbie-Leigh
New Coder

 
Join Date: Jul 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Debbie-Leigh is an unknown quantity at this point
Hi aedrin,

Oh, yes, of course. 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;
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.
Debbie-Leigh is offline   Reply With Quote
Old 11-06-2007, 12:35 AM   PM User | #4
Debbie-Leigh
New Coder

 
Join Date: Jul 2007
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Debbie-Leigh is an unknown quantity at this point
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
__________________
QuicknEasySalesPro.com - your quick and easy, yet powerful solution for managing your membership site sales, downloads and affiliates.
Debbie-Leigh is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:54 AM.


Advertisement
Log in to turn off these ads.