Quazi Marufur Rahman
Quazi Marufur Rahman

Reputation: 2623

mysql update query (containing 'where' syntax) not working

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\r\n', '555', '-0.22\r\n'), ('Platinum\r\n', '555', '-9.00\r\n'), ('Palladium\r\n', '555', '0.00\r\n'), ('Rhodium\r\n', '555', '0.00\r\n');

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 ??

Upvotes: 0

Views: 137

Answers (1)

GoalieGuy6
GoalieGuy6

Reputation: 522

It looks like you have a line break in your _metal_name in the database, the SQL query says Silver\r\n.

Upvotes: 4

Related Questions