Ruby MySQL INSERT variable

k = "50"

my = Mysql::new("localhost", "root", "pass", "table")
my.query("INSERT INTO table VALUES('2008-05', #{k}, 324)")

./Class.rb:212:in `query': Unknown column '50' in 'field list'
(Mysql::Error)

How do I insert a variable into a row?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Well, i solved this by bringing ( ' ' ) around the #{k}. Thus your code is
likely to become like this,
my = Mysql::new("localhost", "root", "pass", "table")
my.query("INSERT INTO table VALUES('2008-05', '#{k}', 324)")

Hope it solves it.

···

On 7/1/08, Justin To <tekmc@hotmail.com> wrote:

k = "50"

my = Mysql::new("localhost", "root", "pass", "table")
my.query("INSERT INTO table VALUES('2008-05', #{k}, 324)")

./Class.rb:212:in `query': Unknown column '50' in 'field list'
(Mysql::Error)

How do I insert a variable into a row?

Thanks
--
Posted via http://www.ruby-forum.com/\.

--
--Ben Baka
Blog : http://benjaminbaka.wordpress.com/