Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2013
    Location
    Texas, USA
    Posts
    35
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Error object Object on return from post

    I'm trying to post a field value to php, check in my db to see if it exists, then return and handle on the form according with a pop up saying what to do. I do also have it backwards, as the registration is invite only so you'll notice in the php that you do in fact have to have your email there.

    It returns "empty" and handles it exactly fine when there is nothing in the field. If I put anything at all in the input though it gives the error and I have no idea why...

    java part, and like it said, it works when its 'empty'
    PHP Code:
    $('form.register_form input[name=email]').bind("oninput", function ()
                {
                    var 
    messageBox = $('form.register_form span#msgbox2');
                    var 
    input = $(this);
                    
                    
    messageBox.removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);

                    var 
    getData = $.post('process_availability.php', { email:input.val() });
                    
    getData.done(function(data) {
                        
    alert(data);
                        
    //if correct login detail
                        
    if (data == 'empty')
                        {
                            
    // blank input
                            
    messageBox.fadeTo(200,0.1,function() { 
                                
    //add message and change the class of the box and start fading
                                
    messageBox.text('Please put in a valid email!').addClass('messageboxerror').fadeTo(900,1);
                            });
                            
    alert('Please put in a valid email!');
                        }
                        if (
    data == 'yes')
                        {
                            
    // email is available
                            
    messageBox.fadeTo(200,0.1,function() { 
                                
    //add message and change the class of the box and start fading
                                
    messageBox.text('This email is available to register!').addClass('messageboxok').fadeTo(900,1);
                            });
                            
    alert('This email is available to register!');
                        }
                        if (
    data == 'no')
                        {
                            
    // email is not in database
                            
    messageBox.fadeTo(200,0.1,function() { 
                                
    //add message and change the class of the box and start fading
                                
    messageBox.text('This email could not be found in our database!').addClass('messageboxerror').fadeTo(900,1);
                            });
                            
    alert('This email could not be found in our database!');
                        }
                        if (
    data == 'already')
                        {
                            
    // email has already been registered
                            
    messageBox.fadeTo(200,0.1,function() { 
                                
    //add message and change the class of the box and start fading
                                
    messageBox.text('This email is already registered!').addClass('messageboxerror').fadeTo(900,1);
                            });
                            
    alert('This email is already registered!');
                        }
                    });
                    
    //.fail(function(jqXHR, textStatus, errorThrown) { alert(textStatus+ ': ' +errorThrown); }).always(function() { alert("finished"); });
                
    }); 
    the php to check
    PHP Code:
    <?php
    //check email availability
    if ($_POST['email'] != null) {
        
    //require necessary files
        
    require('config/dbconfig.php');
        include(
    'classes/class.mysqli.php');
        
        
    //change post to variable
        
    $email $_POST['email'];
        
        
    //set up bind for query
        
    $bind = array(
            
    ":email_bind" => "$email"
        
    );
        
        
    //query email to see if it is in database
        
    $results $db->select('users','email=:email_bind',$bind,'*','','');
        
        
    //use boolean to check results
        
    $trueFalse = (count($results) > 0) ? 1;
        if (
    $trueFalse == 0)
        {
            foreach(
    $results as $row)
            {
                if (
    $row['regcode'] == null)
                {
                    echo 
    'already';
                }else
                {
                    echo 
    'yes';
                }
                exit;
            }
        } else {
            
    //email is blank
            
    echo 'no';
            exit;
        }
    }else
    {
        echo 
    'empty';
    }
    ?>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    May I suggest you double check the PHP code, first?

    Easy to do.

    Temporarily change the two uses of $_POST there to $_GET.

    Then just hit that page from the browser using a URL such as
    Code:
       process_availability.php?email=abc@xyz.com
    That is, passing in both email addresses in the db table and not, already registered and not. Do you get the results you expect?

    If not, fix the PHP code.
    If so, then indeed the but is in the JS code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jan 2013
    Location
    Texas, USA
    Posts
    35
    Thanks
    5
    Thanked 0 Times in 0 Posts
    No I get a HTTP 500 error. Cannot display the webpage.

    That's my db right? Or something else? If i take the ?email=abc@xyz.com part out it does load fine, and says 'empty'.

    I'm using a PDO wrapper to execute the sql queries. The config for the db looks fine too, and this wrapper worked with other things in the past.

    Found it. Might be important to make sure you make a connection first. xD Sorry guys.
    Last edited by gkjr1; 01-25-2013 at 03:21 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Quote Originally Posted by gkjr1 View Post
    Found it. Might be important to make sure you make a connection first.
    LOL! Shame on you. I have certainly never made a silly mistake like that!

    Never today, that is. But, then, I haven't started coding yet today.

    Give me time, I'll do it at least once or twice today.

    *********

    Seriously, if nothing else you now know how to debug the server side of AJAX problems. I use the change-POST-to-GET trick all the time. It has saved me hours of headaches.

    Best of luck!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •