Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving data from client via server to offline db. Help please. 3

Status
Not open for further replies.

Pyrrhus

Technical User
Dec 18, 2001
112
AU
What I have is a website on a remote server which collects data from clients and stores it in a client cookie using javascript. I now want to bring that data via the server to my remote desktop, for inclusion into an offline Access db. This is for offline statistical work only, and I have no need for online db capability, and would prefer to avoid it. I also need to format that client data, currently accessible as javascript variables, into a db record format, either before sending or after. Should I use a form/mail CGI/Perl script? Where can I get one that will allow me to format the variables as fields in a record? Is there a smarter way to do it? Any help will be much appreciated. Thanks.[dazed]
 
Just write the stuff to a log file and write a second CGI to read/parse the log file and spit it back at you.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Thank you goBoating. I'm grateful for your help. But I'm a fairly basic user. I have developed a site using HTML and Javascript, but I"m not a professional programmer or developer.

For example, I don't know how to "just write the stuff to a log file" (presumably a log file on the server). Do I have to use a Perl script to do this? Do I use a standard log file , or do I have to set one up?

If you know where I can find some info on this, I could read up on it.

Likewise, I could probably modify an existing Perl script to "spit it back", but I could not write one from scratch. Any suggestions (other than "get lost")?
 
DON'T be afraid of Perl

If you can code Javascript, you already understand most of the basic constructs, and anything you come across that looks diff.

Holler, with info, of course

Today is the first day of the rest of your life...do something with it

HTH
--Paul
 
Yes the log file would be on the server. If you need more information than is captured in your web server logs, then you'll need to write a little cgi or maybe PHP or other that happens on the server. Static HTML with embedded client-side javascript can't write back to the server. CGI can do that for you. If you think some CGI is in order, see the faqs tab at the top of this forum. There are a few in there about the basics of writing CGIs with Perl. After that, please come back here with any questions.

'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
If you are storing it in the client cookie and really want to stick with Javascript just have javascript email you the contents of the cookie when the appropriate button is clicked.

Don't be afraid of perl but sometimes using perl is not an option and there is a lot to be said for sticking with what you know..


You could use JS to put the contents of the cookie into a hidden form field and have the user submit that form.

I wouldnt do it that way but it fits your parameters..
 
Hello Siberian,

You gave me some help way back, Oct 1 last year, but I had to drop the task and I’m just returning to it now. I just want to clarify your last post, if I may.

You said: “If you are storing it in the client cookie and really want to stick with Javascript just have javascript email you the contents of the cookie when the appropriate button is clicked.”

You then went on to say to use js to put the js cookie contents into a hidden form field and have the user submit the form, and gave me the url of some explanatory code. All this part is clear.

What I’m confused about is the first part of your advice “just have javascript email you the contents of the cookie”. Did you mean to do this in the manner you described later in the same post (ie. set up the form values using JS, using a hidden form and submit, presumably with an action=mailto: ), or is there some other way to do it using JS?

Thanks, and sorry to test your memory like this!

 
Put a form on your page like that shown in the link Siberian provided. Have javascript put the data you need into the values of hidden form fields. The user would then just have to click the button and hopefully their browser would use their e-mail program to send the message.

Siberian probably said he wouldn't use this because 1) you have to manually get the data from these e-mails you receive and input it into the database and 2) it may not be reliable. For example, I use Mozilla for web browsing, but if I viewed your page with Mozilla and submitted the form to send you an e-mail, it would try to use Mozilla's mail program. I don't use Mozilla's mail so it's not set up to be able to send messages, therefore you wouldn't get the info from me. With CGI, you could easily collect the data from the cookies, format it, and store it into a file.

What kind of data are you trying to collect. Could you gather it another way?

 
Hello Philote,

Thanks for your input. I agree with your comments about different browsers. Not only that, but it’s impossible to control the layout of the data in the receiving window, which makes it difficult to use. So far I’ve been getting the user to cut and paste the results matrix as it appears on their screen into their email window. Very crude I know, but even this simple exercise has shown that email delivers the results in varying layout formats.

The original string is in the format
sc0101nnsc0102 ...sc1205nnsc1206nn .. sc4008nn
where sc0101 etc. are the actual js variable names
sc stands for "score"
1205= Topic 12 Question 5.
There are 40 topics, each of 8 questions.

This string is stored as a js cookie on the client and I need to get it back to me, either by email or via the server, so that I can use the data for statistical purposes, and for reporting statistical comparisons back to the user. The user needs to initiate the process, for privacy reasons (which is why I used the js cookie approach in the first place). I break down the string in js on the client, so I can send it back to myself either as a matrix of the 40x8 score values, or as the continuous string. The string also needs to include the user’s email address. Using email, that’s automatic, but would need to be included if the string were sent back any other way.

I’m beginning to think I need to bite the bullet and use a CGI approach. Before I had to move off this problem, Siberian suggested (in a different TekTips stream) that I use CGI.pm and DBI.pm (thanks again Siberian), and I am just now investigating this approach. I’ve looked up CGI.pm description via Google and it seems quite complicated, but I guess I could get on top of it eventually (I’m and old Fortran / PL1 / Assembler programmer from the late 60’s. A veritable dinosaur.)

Sorry if I sound confused, but I am. Any input you can offer would be very welcome. Sounds like I’m screwing around here, but I’m just trying to figure out the effort versus likelihood of success ratio of approaches, given my feeble programming ability.

Thanks again!
 
CGI.pm and DBI.pm are definitely the way to go. I don't know how familiar with perl you are, but the best place to look for info about these modules is Here's the direct links to those modules' docs on cpan:

Basically with CGI.pm you could have something like this to get the cookie:
Code:
use CGI;
$query = new CGI;

$answers = $query->cookie('answers');
print $query->header,
      $query->start_html,
      $answers,
      $query->end_html;
This assumes of course, that your string of variables and answers as in your example is stored in a cookie called 'answers'. You'd then have to parse the string to get the topic and question numbers and their answers. You could then use the Net::SMTP module (again look on cpan) to e-mail the answers to yourself or use DBI to save them to a database.

To get the e-mail address from the user, you'd need to set up a form and have the user enter their e-mail addy in a text field named 'email'. Then in your cgi script you'd have:
Code:
$email = $query->param('email');

Hope that makes sense. Good luck!
 
Hello again Philote,

Thanks for your suggestions. I have spent the past couple of days going through the sites you recommended and the linked sites. I have a better understanding now. One impression I got was that setting up CGI scripts for different servers can be a bit tricky, or at least fiddly (security, etc.). The relevance of this is that I intend to customize my website for other sites, via css, and allow them to install it on their own servers (free both to them and the user, except I will still get the stats). Since html and js are completely transportable (almost) then I concluded that the js approach would be probably better suited to minimize the transport effort. But I have used your suggestions and those of others and now have a much cleaner email of the results matrix which can be virtually automatically loaded up into Excel or Access. So I’m happy with the outcome.

Do you agree with my logic, given my need to keep it simple?

Thanks again.

 
I agree, there's no sense in doing more than you need to. Good luck!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top