Abdul Waheed Abdul Waheed - 2 months ago 6x
PHP Question

Ajax jquery redirecting is not working can you please help out

hi i have a login form when user logs in he has to redirect with session to participant-screen.php but it is not working this in live you can even check here: amerytech.net/learningcurve/login.php

//Ajax script
url: "controller.php",
method: "POST",
data: {
loginData: $("#loginForm").serialize(),
'action': 'login'
dataType: "text",
success: function(response) {
if (response == 'success') {
error: function(request, status, error) {
$("#showMessage").html("OOPS! Something Went Wrong Please Try After Sometime!");

//My controller page
elseif($_POST['action'] == 'login') {
parse_str($_POST['loginData'], $loginData);
$email = $loginData['email'];
$password = md5($loginData['password']);
$LoginQuery = $conn - > query("SELECT * FROM r_participant where email='".$email.
"'") or die(mysql_error());
$checkparticipentCount = mysqli_num_rows($LoginQuery);
if ($checkparticipentCount == 1) {
$participent = mysqli_fetch_assoc($LoginQuery);
if ($participent['status'] != 1) {
echo "Your Account is InActive";

if ($participent['password'] != $password) {
echo "Invalid Password";

please help me out unable to debugit.


You cannot use a header() redirect when you use ajax. Instead you have to redirect in the javascript part of your ajax when the request has been processed successfully. See for example How to redirect to another page in jQuery?.

Note that you would have to send information back from your php script (for example json) so that you can take the appropriate action in javascript.

Apart from that:

  • You have an sql injection problem, you should use a prepared statement instead of injecting variables directly into your query.
  • You should not use md5() for password hashing. See for example How can I store my users' passwords safely?