# Syntax errors

**URL:** <https://www.ruby-forum.com/t/syntax-errors/136153>\
**Category:** Rails\
**Created:** [April 29, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/syntax-errors/136153 "2008-04-29T13:06:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 29, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/syntax-errors/136153/1 "2008-04-29T13:06:59Z")

</div>

I’m sure this is going to be a very silly question but can anyone tell  
me why this code is giving me errors?

require ‘rubygems’  
require ‘mysql’  
db = Mysql.new(‘localhost’, ‘root’, ‘avuzritfanu’, ‘studentevents’)  
begin  
results = db.query “SELECT \* FROM events\_event”  
puts “Number of users #{results.num\_rows}”

results.each\_hash do |row|  
event = { :title=\>row[“title”],  
row[“start\_time”] = “09:00:00” if row[“start\_time”].nil?  
row[“end\_time”] = “17:00:00” if row[“end\_time”].nil?  
:startTime=\>row[“start\_time”],  
:endTime=\>row[“end\_time”]}  
puts "Title of event #{row[“start\_time”]} "  
end  
results.free  
ensure  
db.close  
end

Here’s the errors

mysqlconnect.rb:10: syntax error, unexpected kIF\_MOD, expecting tASSOC  
row[“start\_time”] = “09:00:00” if row[“start\_time”].nil?  
^  
mysqlconnect.rb:12: syntax error, unexpected tASSOC, expecting kEND  
:startTime=\>row[“start\_time”],  
^  
mysqlconnect.rb:13: syntax error, unexpected tASSOC, expecting tCOLON2  
or ‘[’ or ‘.’  
:endTime=\>row[“end\_time”]}  
^  
mysqlconnect.rb:13: syntax error, unexpected ‘}’, expecting kEND

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 29, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/syntax-errors/136153/2 "2008-04-29T13:24:00Z")

</div>

opening an hash assignment:  
event = { :title=\>row[“title”],

within this hash do this: (? can’t work that way ?)  
row[“start\_time”] = “09:00:00” if row[“start\_time”].nil?  
row[“end\_time”] = “17:00:00” if row[“end\_time”].nil?

and go on with hash keys:  
:startTime=\>row[“start\_time”],  
:endTime=\>row[“end\_time”]}

and close it. if those two lines with row[…] are not very tricky and i  
miss this, then it’s wrong. they should be otside the hash or would have  
to look different if their result should somehow become part of this  
hash.

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 29, 2008, 1:24pm UTC](https://www.ruby-forum.com/t/syntax-errors/136153/3 "2008-04-29T13:24:44Z")

</div>

Hi –

On Tue, 29 Apr 2008, vanderkerkoff wrote:

> puts “Number of users #{results.num\_rows}”
> 
> results.each\_hash do |row|

I’m re-ordering your lines, to take the row assignments out of the  
literal hash:

> row[“start\_time”] = “09:00:00” if row[“start\_time”].nil?  
> row[“end\_time”] = “17:00:00” if row[“end\_time”].nil?  
> event = { :title=\>row[“title”],  
> :startTime=\>row[“start\_time”],  
> :endTime=\>row[“end\_time”]}  
> puts "Title of event #{row[“start\_time”]} "

Are you sure you don’t mean row[“title”] there? Also, why are you  
creating the event hash at all? You don’t seem to use it.

> end

David

–  
Rails training from David A. Black and Ruby Power and Light:  
INTRO TO RAILS June 9-12 Berlin  
ADVANCING WITH RAILS June 16-19 Berlin  
INTRO TO RAILS June 24-27 London (Skills Matter)  
See [http://www.rubypal.com](http://www.rubypal.com) for details and updates!

---

<div class="post-metadata">

**Author:** ![vanderkerkoff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7feea3/32.png) [@vanderkerkoff](https://www.ruby-forum.com/u/vanderkerkoff)\
**Post date:** [April 29, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/syntax-errors/136153/4 "2008-04-29T14:14:12Z")

</div>

Hi David

It’s just a snippet of the entire code, the events hash will  
eventually be used to populate a google calendar.

Hopefully

🙂
