Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:14:36+00:00 2026-06-15T01:14:36+00:00

My code run’s through fine but fails when it gets to the success call.

  • 0

My code run’s through fine but fails when it gets to the success call. On the ajax section “if (result.success){” it shows an error in the browsers sources tab with result being null.

Login Page:

<form id="login_form_header">
    <input type="hidden" name="action" value="sc_ajax_callback" />
    <input type="hidden" name="func" value="sc_login" />

    Email:
    <input type="text" name="username" />

    Password:
    <input type="password" name="password"/>

    <input type="submit" value="Log in" />
</form>
<script>
$("#login_form_header").submit(function(event){

    event.preventDefault();

    $.ajax({
        type: 'post',
        url: '<?php echo get_stylesheet_directory_uri(); ?>/connect.php',
        data: $('#login_form_header').serialize(),
        dataType: 'json',
        success: function(result){
            if (result.success){
                window.location = "my-dashboard/";
                return false;
            };
        },
        error: function(e){console.log("Could not retrieve login information")}
    });

    return false;
});
</script>

Connect Page:

<?php 

    mysql_connect("localhost", "%user%", "%pass%") or die(mysql_error()); // Connect to database server(localhost) with username and password.
    mysql_select_db("%db%") or die(mysql_error()); // Select registration database.
    # Make sure form data was passed to the script
    if(isset($_POST['username']) && !empty($_POST['username']) AND isset($_POST['password']) && !empty($_POST['password'])){

    # Define Variables
    $active_var = "1";
    $given_username = mysql_escape_string($_POST['username']);
    $given_password = dosomethingtopass;
    $matched_username = "";
    $matched_password = "";

     # See if there is matching info in the database
    $sql = 'SELECT username, password, active FROM %table% WHERE username="'.$given_username.'" AND password="'.$given_password.'" AND active="'.$active_var.'"'; 
    $result = mysql_query($sql);
    while($row = mysql_fetch_assoc($result)){
    if($given_password == $row['password']){
        $matched_username = $row['username'];
        $matched_password = $row['password'];
        }
    };

    # If there was a match 
    if($matched_username != "" && $matched_password != ""){
        #If there is only one result returned
        echo json_encode(array("$matched_password"));
        $session_sql = 'SELECT id, username, password, last_login FROM %table% WHERE username="'.$matched_username.'" AND password="'.$matched_password.'"';
        $session_result = mysql_query($session_sql);
        while($returned_row = mysql_fetch_assoc($session_result)){
            if($matched_password == $returned_row['password']){ 


            $_SESSION['id'] = $returned_row['id'];
            //$_SESSION['last_login'] = $returned_row['last_login'];
            $_SESSION['username'] = $returned_row['username'];
                }
             }

            $date = date('Y-m-d H:i:s');
            $update_sql = "UPDATE %table% SET last_login='".$date."'";
            mysql_query($update_sql);

        echo json_encode(array("success"=>"user logged in", "session"=>$_SESSION));
        }
    }

?>

Also the update_sql is updating every row in my table kinda odd. Not sure where I am going wrong any help?

EDIT:

Updated

   $.ajax({
        type: 'post',
        url: '<?php echo get_stylesheet_directory_uri(); ?>/connect.php',
        data: $('#login_form_header').serialize(),
        dataType: 'json',
        success: function(result){

                window.location = "my-dashboard/";

            };
        },
        error: function(e){console.log("Could not retrieve login information")}
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:14:37+00:00Added an answer on June 15, 2026 at 1:14 am
    success: function(result){
                if (result.success){
                    window.location = "my-dashboard/";
                    return false;
                };
    

    change to

    success: function(result){                    
                        window.location = "my-dashboard/";                     
                    }
    

    result here is te data sent by the server, not an object.


    Also the update_sql is updating every row in my table kinda odd

    It is because there is no WHERE clause in your UPDATE query.

    From the documentation:

    The WHERE clause, if given, specifies the conditions that identify which rows to update. With no WHERE clause, all rows are updated.

    More info here

    EDIT after update

    you have an extra };.

    change

    success: function(result){
    
                    window.location = "my-dashboard/";
    
                };
            },
    

    to

    success: function(result){
    
                    window.location = "my-dashboard/";
    
    
            },
    

    A few point worth to mention:

    • Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks will be deprecated in jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.

    • mysql_* functions are being deprecated. Use PDO instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this code run firefox , but error on ie why ? please help me.
This code run on Turbo C but not on gcc compiler Error:syntax error before
my jquery code not run with IE6 but runs all others including IE7. It
In .Net 4 this code run with no error class A { public event
So far I have this code run when the X button is clicked, but
my code run smooth when I run in main file but when I make
I'm unsure of it's technical term, but it makes my lua code run, and
This code run on Chrome, FF, Safari, IE9 but on IE8 i get this
I have a C++ native code that run fine in Debug and Release mode.
This javascript code run without problem in chrome and IE but have a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.