Redirect with jQuery and PHP

1

I have two pages, where one is the .js which makes the ajax call to a routine in PHP to validate a user: link

Another page in PHP that is the call of this previous routine where I will validate the user by his login and password to send it to the rest of the site: link

On line 23 and 24 I make a insert in a log table, however, when I do this, I have the JSON return to the page that called this routine; on page .js this PHP return comes right, but on line 23 we have a redirect to index_adm.php , but jQuery is not doing it.

When I comment on line 23 and 24 (that is, insert in the log table in link ) redirection works fine. Only when I insist on doing this insert does it not work. I do not understand why.

    
asked by anonymous 14.11.2017 / 01:45

1 answer

0

Why do not you try to "prepare" and "run" to see if php is not generating an error when you insert it?

        $erros = array();

        $sql_in ="INSERT INTO log_user_on (fk_id_user_sistema,log_user_on_login_data) VALUES ( ?, ? ) ";

        // prepare 
        if ($stmt = $conn->prepare($sql_in)){

            //bind
            $stmt->bind_param("ss", $id_user, $hoje );

            //execute
            if ( $stmt->execute() ) {

                // echo "\n New records created successfully";

            }else{
                $erros["execute_error"] = $conn->error;
            }

            //close
            $stmt->close();

        }else{

            $erros["prepare_error"] = $conn->error;

        }

        $conn = null;

        $response = array("success" => true,"login"=>$varLogin,"id_user"=>$id_user,"token"=>$token, "erros"=>$erros);

        echo json_encode($response);
    
14.11.2017 / 05:11