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 “”
puts “”
puts “Input request”
puts “”
puts “

Your name is #{fn} + #{sn}


puts “

Your general information:

puts “Age: #{age}

puts “Gender: #{gender}

puts “Email Address: #{em}


puts “”
puts “”

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 `', referer:
http://localhost:10000/

Thanks
Adam K

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

open(’/media/Apache/apache2/logs/visitor_log’, ‘a’)

-Ryan V.

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

On Wed, 09 Jan 2013 20:21:06 +0100, Adam K. [email protected]
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)".

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
}

On 1/9/13 1:21 PM, Adam K. wrote:

fn = cgi.params[‘forename’]
puts “

Your name is #{fn} + #{sn}


f.puts email
/media/Apache/apache2/cgi-bin/hello1.cgi:26:in `initialize’: No such
Adam K

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

open(’/media/Apache/apache2/logs/visitor_log’, ‘a’)

-Ryan V.

Bartosz Dziewoński wrote in post #1091631:

On Wed, 09 Jan 2013 20:21:06 +0100, Adam K. [email protected]
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