Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    59
    Rep Power
    6
    Maybe it should be moved, but I still believe this can be a PHP issue, which I'm going to explain why it may be a PHP issue.

    I changed the .ajax() request to the following:
    Code:
    			$.ajax({
    			  type: "POST",
    			  dataType: 'json',
    			  cache: false,
    			  url: "Scripts/confirmform.php",
    			  data: { 
    				  origEmail: origEmail,
    				  confirmEmail: confirmEmail,
    				  name: name,
    				  age: age,
    				  gender: gender,
    				  country: country,
    				  catcher: catcher,
    				  addition: addition,
    				  mathAnswer: mathAnswer,
    				  submissionTime: submissionTime 
    			  },
    			  success: function(data) {
    				alert("success");
    				console.log(data);
    				testSecondResults(data);
    			  },
    			  error: function(data) {
    				alert("error");
    				console.log(data);   
    			  },
    			  complete: function() {
    				alert("done");
    			  }
    			});
    If I put a valid submission on everything, I get the alert message of 'error'. When using a unique e-mail not already in the database, the user's data is written (success) but the AJAX call is an overall failure and won't display what it should do as coded in testSecondResults().

    If I do an invalid submission, the AJAX request is successful, and I see the success alert message.

    This all seemed to be going wrong soon after I got the database writing set up.

    It may mean that it does not like how my PHP is set up for some reason. If you look at confirmform.php, you'll notice that all the common errors (no name, no e-mail submitted to compare to, no location set), those are all caught in the massive if-elseif block near the beginning. If the submission appears to be valid, a variable named $status is set to 1 and the following code is executed, which given the current behavior, may be where the problem is stemming from.

    PHP Code:
    if ($status === 1) {
                    require_once(
    "categoryfinder.php");
                    
    $categoryFinder = new CategoryFinder;
                    
    $category $categoryFinder -> getCategory();
                    
                    
    $response['validation'] = "pass";
                    
    $response['message'] = "Thanks for joining the e-mail list, <b>" $name "</b>, under the e-mail address, <b>" $confirmEmail "</b>.";
                            
                    require_once(
    'databasewriter.php');
                    
    $dbWriter = new DatabaseWriter;
                    
    $dbCode $dbWriter -> writeUserToDatabase($confirmEmail$name$ageRange$gender$country$category);
                    
                    echo 
    '    database code: ' $dbCode;
                    if (
    $dbCode === 1) {
                        
    $response['database'] = "pass";
                        echo 
    'Database Write Successful';
                    } else {
                        
    $response['database'] = "fail";
                        
    $response['validation'] = "fail";
                        echo 
    'Database Write Failure';
                    }
                    if (
    $dbCode == 2) {
                        
    $response['message'] = "Server error. Please try again later.";
                    } elseif (
    $dbCode == 3) {
                        
    $response['message'] = "That e-mail address already exists.";
                    }
                }
            
                echo 
    json_encode($response);
            }
        } 
    Many thanks as always.
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,540
    Rep Power
    595
    Just so we don't wind up chasing our tails, did you echo $response to verify it contains what you expect? If it does then obviously it is not PHP. If not then what does it contain and what do you expect?

    As an aside, I still see you are using '===' rather than '==' which might get you into trouble unless you really understand the difference and how PHP handles variable typing.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    59
    Rep Power
    6
    Okay, I changed all '===' to '==' and re-uploaded. I see exactly what I want to see from the PHP, so this is a JavaScript issue.

    This thread needs transferring over to that forum.
  6. #19
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    I don't want to make the JavaScript guys slog through 18 posts to get to the JS question. Can you just make a new thread there and link back to this one for reference?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #20
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    59
    Rep Power
    6
    I thought I might come back to this thread and share the solution, especially since no one responded to the JavaScript thread I posted about this issue.

    There were a couple of echo statements inside that script that were gumming up the AJAX request, and they were the ones that said "Database Write Successful" or "Database Write Failure". They were ruining my script.

    Thanks for all you did for me and God Bless You.
  10. #21
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Ah, interesting.

    Using the firebug or google chrome console would have shown ajax/json parse errors.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #22
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Location
    Atlanta, GA, USA (unfortunately)
    Posts
    59
    Rep Power
    6
    It did. I just had to get other help to set up the AJAX request to return those parse errors into the console.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo