Nevermind.  Three hours after embarking on my voyage to insanity I finally
figured it out.  If I type cast the variables as strings the error
dissapears.  I've never had this problem before though.. so its still a bit
of a mystery since the data stored in the variables are most certainly
strings and a direct comparison to an identical string (without type
casting)  returns true.

$keyword = (string)$index[$i]['word'];
$pagelist = (string)$index[$i]['pages'];

-Kevin

----- Original Message -----
From: "Kevin Stone" <[EMAIL PROTECTED]>
To: "PHP-general" <[EMAIL PROTECTED]>
Sent: Wednesday, May 22, 2002 4:06 PM
Subject: [PHP] MySQL INSERT concatonating one of my values for seemingly no
reason...


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
[EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to