MySQL INSERT concatonating one of my values for seemingly no reason...
| From: | Kevin Stone | Date: | Wed, 22 May 2002 22:06:45 +0000 |
| Subject: | MySQL INSERT concatonating one of my values for seemingly no reason... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-98829@lists.php.net to get a copy of this message | ||
I have an array containing data from a search engine index. The array contains only two values..
"word" and "pages" which will be stored in a MySQL table.
$index[$i]['word'] //contains the keyword.
$index[$i]['pages'] // contains a comma delimited list of pages the keyword exists on.
If you print out the values stored in the first index in the array this is what you get...
echo $index[0]['word']; // prints "test"
echo $index[0]['pages']; // prints "test.html,test2.html"
However when inserting the values into the database results in a concatonation of the
'pages' value at the first comma...
$query = "INSERT INTO
legends_search (keyword, pages)
VALUES ('".$index[0]['word']."',
'".$index[0]['pages']."')";
mysql_query($query, $db);
// Let's just see what it's imputing..
echo $query; // prints "INSERT INTO legends_search (keyword,
pages) VALUES ('test', 'test.html,test2.html')"
results:
-----------------------------------
keyword pages
test test.html
----------------------------------
Why is the pages value being concatonated!? I thought perhaps I was inserting an invalid character
so I did a test by setting a two variables to the desired values then inserting them into the
database.
$word= 'test';
$pages = 'test.html,test2.html';
$query = "INSERT INTO legends_search (keyword, pages)
VALUES ('$word', '$pages')";
mysql_query($query, $db);
// Let's just see what it's imputing..
echo $query; // prints "INSERT INTO legends_search (keyword,
pages) VALUES ('test', 'test.html,test2.html')"
results:
-----------------------------------
keyword pages
test test.html,test2.html
----------------------------------
This worked exactly as I expected. The pages collumn was populated with the full value and
didn't get concatonated. So why was it being concatonated when the same value was being read
from the array? Perhaps there was something wrong with the value in the array. So on that premis I
checked the array value against a the static variable that I defined in the second test...
$pages = 'test.html,test2.html';
if ($pages == $index[0]['pages'])
echo "TRUE";
else
echo "FALSE";
And it echos TRUE every time. So it has to be an identical string. Yet when I insert from the
array values 'pages' gets concatonated at the first comma. As far as I can tell both
methods are inserting the same exact values (just look at the $query echo statements above for more
proof). I can not understand why the 'pages' value is being concatonated when inserted
from the array. Any help? Or are you just as baffled as me.
Much thanks,
Kevin Stone
kevin@helpelf.com