I have an array defined like so:
I am trying to update a mysql table called Ocean that has fields 'RCVD' and 'REF_NO' among others with the following SQL:PHP Code:$combined = Array
(
[28-04-05] => 9873-9874
[23-01-04] => 3054887
[11-02-04] => 3076388
[20-05-04] => 3078718
[24-05-04] => 3133455
[29-04-04] => 3122869
[09-04-04] => OC04103
[07-09-04] => 3134649
[20-09-04] => 3301564
[08-07-04] => OC0441
[03-02-05] => 3503233
[05-11-04] => 3374477
[21-09-04] => 3345523
[22-09-04] => 3314203
[28-09-04] => LK0486
[21-10-04] => 3345879
[03-12-04] => 3431131
[04-01-05] => 3459872
[13-04-05] => 3596663
[03-03-05] => LK04136
[21-04-05] => 3610857
[07-04-05] => 3566293
[01-11-02] => HOVCHILD
[11-11-04] => LK04106
[14-02-05] => OC05006
[15-12-04] => OC04102
[12-02-04] => LK0425
[21-07-04] => OC0442
[27-08-04] => oa41
[19-01-05] => OC05004
[20-08-03] => oa4
[??] => oa8
[08-09-04] => oa14
[0719/04] => oa16
[17-08-04] => oa18
[25-10-04] => oa38
[14-07-04] => oa5
[13-03-02] => oa46
[15-07-02] => oa6
[30-07-02] => oa7
[16-07-03] => oa9
[15-07-04] => OC0419
)
This returns the following to the browser window:PHP Code:foreach($combined as $RCVD => $REF_NO)
{
$sql = "UPDATE `Ocean` SET `RCVD` = '" .$RCVD ."' WHERE `REF_NO` =" .$REF_NO ." LIMIT 1 ;";
$result = mysql_query($sql);
if (mysql_query($sql))
{
echo("<p class=\"content\">Information updated.</p>");
}
else
{
echo("<p class=\"content\">Error updating information: ");
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $sql . "</p>";
die($message);
}
}
It seems that all goes well until the loop reaches an array value begining with a letter rather than a digit, e.g.Information updated.
Information updated.
Information updated.
Information updated.
Information updated.
Information updated.
Information updated.
Error updating information: Invalid query: Unknown column 'OC04103' in 'where clause' Whole query: UPDATE `Ocean` SET `RCVD` = '09-04-04' WHERE `REF_NO` =OC04103 LIMIT 1 ;That is a letter O not a zero at the begining of the value. How can I fix this? I've tried to enclose the value with backticks like this:[09-04-04] => OC04103but this didn't help.[09-04-04] => `OC04103`![]()
Heeeeelp someone!
Thanks.


LinkBack URL
About LinkBacks





Reply With Quote

Bookmarks