Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #14903

Re: Newby neds help

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: Newby neds help
Date 2015-02-07 21:33 -0500
Organization A noiseless patient Spider
Message-ID <mb6ht6$b5r$1@dont-email.me> (permalink)
References <6rtcdahf5gqka5aavks1kub18uoqnd7ajl@4ax.com>

Show all headers | View raw


On 2/7/2015 3:38 PM, F. George McDuffee wrote:
> About me: Nyme Unka_George. I am a long time lurker on this
> group and a retired academic with some obsolete web design
> experience [Front Page].  I am attempting to learn HTML5,
> Javascrip, and PHP at the same time, and have made some
> progress [got a cut and paste hit-counter working].
> 
> General problem for group: I can't get a tab delimited
> formatted string to transfer from a client side web survey
> which uses Javascript to score a survey [which is working
> see  http://mcduffee-associates.us/MDI05g.html ] to a server
> side PHP program which will append the tab delimited
> formatted string to an existing tab delimited file [which is
> also working, using inline dummy data.  The PHP program is
> shown below.  PHP is running locally on XAMPP v3.2.1  
> 
> Background: Survey is from the World Health Organization and
> measures depression.  The survey has been validated across a
> number of cultures.  My interest is in determining the
> extent and degree of depression in rural/micro urban areas
> as part of RED [Rural Economic Development] effort, and by
> doing multiple regression analysis of the depression and
> demographic data determine how much, if any, correlation
> exists job status, housing, living arrangements, length of
> commute, job tenure, type of housing, etc.  This is
> important because depression, both “overt” which this survey
> attempts to measure, and “masked” depression have been shown
> to closely associated with “learned helplessness,” [subject
> of another survey in preparation] which if prevalent will
> prevent a community growth/development even when
> opportunities are available.  Therefore this must be
> corrected, either before, or concurrent with, any economic
> development efforts if these are to succeed.  My web RED web
> page, along with some earlier versions on the survey in
> Visual Basic can be seen at
> http://mcduffee-associates.us/RED/redmain.htm   
> 
> what I think is the important part of the Javscript program
> is
<snip>

First of all, forget Christoph M. Becker's comments.  He's just a troll,
only capable of (mis)quoting standards and trolling.

As for your problem - there are several ways of doing this.  Personally,
I would just POST the form to the server and have the PHP code create
the tab-delimited string.  Even better would be to use fputcsv() to
write the string to a .csv file.

You can get what you have here to work, but it's going to take a bit of
debugging.  Your first step should be to separate your attempt into two
separate pieces.

You didn't post all of the javascript (which would be off-topic here,
anyway), but my suggestion would be to get that piece working first.
Lew already gave you some good comments on problems in your javascript
code; you should be able to get more help on that part from
comp.lang.javascript.

As for debugging - create a PHP page which simply saves the data it gets
to a file - nothing more.  Now strip your javascript to the absolute
minimum required (i.e. send one field, unformateed), and get that
working.  Now add additional code, one piece at a time, and get it working.

Alternatively, use a javascript debugger such as Firebug on Firefox to
debug your javascript and get it to send the proper information.

Once you have the javascript working, start adding code to your PHP file
to do what you need.

Also, think about your code.  What do you actually need?  For instance,
is the IP address really important?  If not, leave it out.  You can
always add code later when you get it working.

Also - normally for a PHP development system (you DO have a development
system separate from your production system, right), I normally
recommend your php.ini file contains:

error_reporting = E_ALL
display_errors = On

However, this doesn't help when you're using AJAX because errors in
handling an AJAX request aren't displayed.  So for this reason I also
recommend you have

log_errors = On
error_log = (full path to a file here)

BTW - it's easy to change the wrong php.ini file.  To find the one being
used, just create a file with only the following line:

<?php phpinfo(); ?>

Upload it to the root directory of your web server and load it in your
browser.  One of the things it will show is the php.ini file being used.

As for an alternative (and easier) implementation - just put all of your
input fields in a form and POST it to the server.  No javascript
required on the client side (unless you wish to validate data before it
is sent).

Now on the server side, your PHP gets all of the data from the $_POST
array and builds a tab-delimited string and writes the string to a file
(an even better way, IMHO, would be to build an array of parameters and
use fputcsv() to write as a .csv file).  Much more straightforward and
easier to implement.

But whichever way you go, I can't stress enough - validate EVERY piece
of information coming from the client.  This means data type and value
for each item, to ensure it is good.  Never trust anything from the client.

I know this is kinda long - but I hope it helps some.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-07 14:38 -0600
  Re: Newby neds help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-07 16:31 -0500
  Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-07 23:30 +0100
  Re: Newby neds help Tim Streater <timstreater@greenbee.net> - 2015-02-07 22:36 +0000
  Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 00:06 +0000
    Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 01:29 +0100
      Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 20:22 -0500
        Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 02:33 +0100
          Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 20:54 -0500
      Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 13:27 +0000
        Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 15:22 +0100
          Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-08 21:58 +0100
            Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 22:56 +0100
              Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-08 23:36 +0100
                Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:14 +0100
                Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-09 00:42 +0100
                Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:58 +0100
                Re: Newby neds help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-09 00:30 +0100
                Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 00:53 +0100
          Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-08 21:46 +0000
            Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-09 00:40 +0100
              Re: Newby neds help Denis McMahon <denismfmcmahon@gmail.com> - 2015-02-09 19:34 +0000
                HTTP (was: Newby neds help) "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 02:04 +0100
        Re: Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-08 20:06 -0600
          Re: Newby neds help Matthew Carter <m@ahungry.com> - 2015-02-08 21:55 -0500
            Re: Newby neds help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-09 00:13 -0600
          Re: Newby neds help Tim Streater <timstreater@greenbee.net> - 2015-02-09 09:46 +0000
          Re: Newby neds help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-10 01:14 +0100
    Re: Newby needs help F. George McDuffee <gmcduffee@mcduffee-associates.us> - 2015-02-07 19:29 -0600
      Re: Newby needs help "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-02-08 02:40 +0100
      Re: Newby needs help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-07 21:36 -0500
  Re: Newby neds help Jerry Stuckle <jstucklex@attglobal.net> - 2015-02-07 21:33 -0500
  Re: Newby neds help Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-02-09 20:02 -0500

csiph-web