On 17.01.2013 15:31, Adam K. wrote:
a = f.readlines
f.puts a[0]
puts “Thank you”
puts “”
puts “”
puts “
Thank you for your bid, it will now be logged and you will
be
redirected now.
”
puts “”
puts “”
If I understand your question correctly (and I’m not 100% sure I do!),
one simple way to achieve what you want with your existing code would be
to have a hidden form element in the submit page that your second script
reads and then determines which of your 12 files to edit. E.g: (WARNING
UNTESTED!) Your first script looks like:
#Displaying information
#!/media/Apache/ruby/bin/ruby
#!/usr/local/bin/ruby
#encoding: utf-8
puts “Content-type: text/html\n\n”
#Adds information from david.txt to an array
f = File.open("…/logs/david.txt")
a = f.readlines
puts “”
puts “”
puts “David Quetta - Nothing But the Beat”
puts “”
puts “”
puts “
Name :”
puts a[0]
puts “
”
puts “
Description :”
puts a[1]
puts “
”
puts “
Price :£”
puts a[2]
puts “
”
puts “
Item Number :”
puts a[3]
puts “
”
puts “”
puts “Bid: £”
puts "
puts “”
puts “
”
puts “
Please enter in the format £0.00”
puts “”
puts “”
puts “”
And your second script something like:
#!/media/Apache/ruby/bin/ruby
#!/usr/local/bin/ruby
files = {‘David’ => ‘…/logs/david.txt’}
#Sets params for form data
require ‘cgi’
cgi = CGI.new()
bid = cgi.params[‘bid’]
item = cgi.params[‘item’]
#Adds information from david.txt to an array
f = File.open(files[item])
a = f.readlines
a[2] = bid
File.open(files[item], ‘w’) { |f|
f.puts a[0]
f.puts a[1]
f.puts a[2]
f.puts a[3]
}
puts “Content-type: text/html\n\n”
puts “”
puts “<meta http-equiv=“REFRESH”
content=“4;url=/cgi-bin/david.cgi”>”
puts “Thank you”
puts “”
puts “”
puts “
Thank you for your bid, it will now be logged and you will be
redirected now.
”
puts “”
puts “”
I assume this is a learning exercise, but if not you probably want to
start thinking about web frameworks and a database backend as this
system doesn’t really scale in any sensible way. And the puts “”
bits burn my eyes.