I have a mysql table like this (sql):
CREATE TABLE IF NOT EXISTS
silver_and_pgm
(_metal_name
varchar(30) NOT NULL,_bid
varchar(30) NOT NULL,_change
varchar(30) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;--
-- Dumping data for table
silver_and_pgm
INSERT INTO
silver_and_pgm
(_metal_name
,_bid
,_change
) VALUES ('Silver ', '555', '-0.22 '), ('Platinum ', '555', '-9.00 '), ('Palladium ', '555', '0.00 '), ('Rhodium ', '555', '0.00 ');
and i am using the following code to update a row which contains metal_name as Silver
<?php
$username = "root";
$password = "1234";
$database = "kitco";
$con=mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$bid = '101010';
$metal_name = 'Silver';
$query = "update silver_and_pgm set _bid='$bid' where _metal_name='$metal_name'";
//$query2 = "update silver_and_pgm set _bid='444'";;
echo $query."<br>";
$result = mysql_query($query);
if(!$result)echo "error";
?>
but $query doesn't work . it works fine if I use $query2 . If I use the same query directly in SQL of phpmyadmin result is same. what is the problem with $query . I think its correct. Would anybody please find the bug ??
It looks like you have a line break in your _metal_name in the database, the SQL query says Silver
.