Sending HTML form information to a text file or visitor_log

The Subject says it all really. I am trying to have the information send
from a simple html form to a text file or visitor_log.
This is my Code:

#!/media/Apache/ruby/bin/ruby
#!/usr/local/bin/ruby

require "cgi"

cgi = CGI.new()
fn = cgi.params['forename']
sn = cgi.params['surname']
em = cgi.params['email']
age = cgi.params['age']
gender = cgi.params['gender']
puts cgi.header("text/html")

puts "<html>"
puts "<head>"
puts "<title>Input request</title>"
puts "<body>"
puts "<p>Your name is #{fn} + #{sn}</p>"
puts "<p>Your general information:<br />"
puts "Age: #{age}<br/>"
puts "Gender: #{gender}<br />"
puts "Email Address: #{em}</p>"
puts "</body>"
puts "</html>"

open('media/Apache/apache2/logs/visitor_log', 'a') { |f|
f.puts forename
f.puts surname
f.puts email
f.puts age
f.puts gender
}

The information is displayed but then nothing actually happens within
the visitor_log file. The piece of code im using was originally found
here:http://www.ruby-forum.com/topic/202526

And this is from my error log:
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1]
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `initialize': No such
file or directory - media/Apache/apache2/logs/visitor_log
(Errno::ENOENT), referer: http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `open', referer:
http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `<main>', referer:
http://localhost:10000/

Thanks
Adam K

···

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

I think you're missing a '/' at the beginning of the path, it should be

open('/media/Apache/apache2/logs/visitor_log', 'a')

-Ryan Victory

···

On 1/9/13 1:21 PM, Adam Kennedy wrote:

The Subject says it all really. I am trying to have the information send
from a simple html form to a text file or visitor_log.
This is my Code:

#!/media/Apache/ruby/bin/ruby
#!/usr/local/bin/ruby

require "cgi"

cgi = CGI.new()
fn = cgi.params['forename']
sn = cgi.params['surname']
em = cgi.params['email']
age = cgi.params['age']
gender = cgi.params['gender']
puts cgi.header("text/html")

puts "<html>"
puts "<head>"
puts "<title>Input request</title>"
puts "<body>"
puts "<p>Your name is #{fn} + #{sn}</p>"
puts "<p>Your general information:<br />"
puts "Age: #{age}<br/>"
puts "Gender: #{gender}<br />"
puts "Email Address: #{em}</p>"
puts "</body>"
puts "</html>"

open('media/Apache/apache2/logs/visitor_log', 'a') { |f|
f.puts forename
f.puts surname
f.puts email
f.puts age
f.puts gender
}

The information is displayed but then nothing actually happens within
the visitor_log file. The piece of code im using was originally found
here:Sending form data to a text file - Ruby - Ruby-Forum

And this is from my error log:
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1]
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `initialize': No such
file or directory - media/Apache/apache2/logs/visitor_log
(Errno::ENOENT), referer: http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `open', referer:
http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `<main>', referer:
http://localhost:10000/

Thanks
Adam K

Well, this errors is pretty clear, isn't it? "No such file or directory - media/Apache/apache2/logs/visitor_log (Errno::ENOENT)".

···

On Wed, 09 Jan 2013 20:21:06 +0100, Adam Kennedy <lists@ruby-forum.com> wrote:

And this is from my error log:
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1]
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `initialize': No such
file or directory - media/Apache/apache2/logs/visitor_log
(Errno::ENOENT), referer: http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `open', referer:
http://localhost:10000/
[Wed Jan 09 19:13:33 2013] [error] [client 127.0.0.1] \tfrom
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `<main>', referer:
http://localhost:10000/

--
Matma Rex

Just an update managed to fix the problem.

Had not defined the correct variable names!
Such a stupid mistake.

File.open('/media/Apache/apache2/logs/visitor_log', 'a') { |f|
f.puts fn
f.puts sn
f.puts em
f.puts age
f.puts gender
f.puts Time.new
}

···

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

I think you're missing a '/' at the beginning of the path, it should be

open('/media/Apache/apache2/logs/visitor_log', 'a')

-Ryan Victory

Thanks Ryan,
Ive just changed it. But still getting a 500 internal Server error on
the page. Also changed the permissions to 777 so that it can write to
that file. Still nothing working yet, but thanks for finding that error
:slight_smile:

Adam K

···

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

Bartosz Dziewoński wrote in post #1091631:

···

On Wed, 09 Jan 2013 20:21:06 +0100, Adam Kennedy <lists@ruby-forum.com> > wrote:

http://localhost:10000/

Well, this errors is pretty clear, isn't it? "No such file or directory
- media/Apache/apache2/logs/visitor_log (Errno::ENOENT)".

Yeah sorry, pretty new to all of this. Ryan cleared things up thanks.

Adam K

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