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
on 2013-01-09 20:21
on 2013-01-09 20:25
On 1/9/13 1:21 PM, Adam Kennedy wrote: > fn = cgi.params['forename'] > puts "<p>Your name is #{fn} + #{sn}</p>" > 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 Victory
on 2013-01-09 20:29
> 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 :) Adam K
on 2013-01-09 20:33
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)".
on 2013-01-09 20:34
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 2013-01-09 20:35
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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.