Jump to content

need help in the code below


doforumda

Recommended Posts

hi

i am facing problem, i dont know what is it, with the code that runs on firefox and chrome absolutely perfect but on IE 8 and safari it does not working. And i also dont know which code is making problem and where should i post this. so please help if you know what is the problem.

 

This page is actually a login page consist of xhtml, ajax and php. When user enters email and pass and press login then a preloader appears and stucks there and doing nothing else. This happens on IE and safari.

here is the code

 

xhtml code

<link type="text/css" rel="stylesheet" href="css/style.css" />
<title>remindme</title>
<div class="loader">
<img src="images/ajax-loader.gif" width="27" height="27" />
    <div class="processing">Processing...</div>
</div>
<div class="login_banner">
Welcome to <div class="banner"></div>
</div>

<div class="login_border">
    <div class="login_form">
        <div class="login_heading">
            Login to <div class="remind"></div>
        </div><!-- login_heading -->
        <form id="login_form" action="main.php" method="post">
            <div>
                <label>Email address:</label>
                <input type="text" name="email" id="email" class="login_input" />
            </div>
            <div>
                <label>Password:</label>
                <input type="password" name="password" id="password" class="login_input" />
            </div>
            <div>
                <input type="button" name="loginbtn" id="loginbtn" value="Login" />
            </div>
        </form>
    </div><!-- login_form -->
</div><!-- login_border -->
<div class="error"></div>
<script type="text/javascript" src="lib/jquery-1.4.min(Production).js"></script>
<script src="js/script.js" type="text/javascript"></script>

 

here is jquery and ajax part

$(document).ready(function () {
//This is function triggers when login button is clicked.
$('#loginbtn').click(function (){
	hideshow('loader',1);
	var url = "login.php";
	//var queryString = $("#login_form").serialize();
	var email = $('#email').val();
	var password = $('#password').val();
	var queryString = 'email=' + email + '&password=' + password;
	//alert(email);
	//alert(queryString);
	$.ajax({
		type: "POST",
		url: url,
		data: queryString,
		dataType: 'json',
		success: show_login
	});		
});

//This function triggers when loginbtn process is successfully completed.
function show_login(resultData) {
	if(resultData.error=='no') {
		$('.error').css('visibility','hidden');
		$('#login_form').submit();
		hideshow('loader',0);
	}
	else {
		hideshow('loader',0);
		$('.error').html(resultData.fieldErrors).css('visibility','visible');
	}
}
});

 

here is php

<?php
session_start();

$email = $_POST['email'];
$password = $_POST['password'];
$error = 'yes';

$connect = mysql_connect("localhost","user","pass");
$db = mysql_select_db("db");

if($email) {
	if(ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
		if($password) {

			//echo $password."<br>";
			$check_email = mysql_query("SELECT * FROM users WHERE email='$email'") or die(mysql_error());
			$count_email = mysql_num_rows($check_email);
			if($count_email > 0) {
				while($row_data = mysql_fetch_assoc($check_email)) {
					$userid = $row_data['userid'];
					$email_db = $row_data['email'];
					$password_db = $row_data['password'];
					$active_db = $row_data['active'];
				}
				//$check_password = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$password'");
				$password = md5($password);
				//echo $password."<br>".$password_db;
				if($email==$email_db&&$password==$password_db) {
					//$check_active = mysql_query("SELECT * FROM users WHERE email='$email' AND active='0'");
					//$count = mysql_num_rows($check_active);
					if($active_db == 1) {
						$get_data = mysql_query("SELECT * FROM profile WHERE userid='$userid'");
						while($row = mysql_fetch_assoc($get_data)) {
							$fullname = $row['fullname'];
						}//end of while($row = mysql_fetch_assoc($get_data))
						$_SESSION['email'] = $email;
						$_SESSION['fullname'] = $fullname;
						$_SESSION['userid'] = $userid;
						$error = 'no';
						$msg = "You are in.";
						//header("Location: page_home/home.php");
						//echo $_SESSION['email']."<br>".$_SESSION['fullname']."<br>".$_SESSION['userid']."<br><a href='logout.php>Logout</a>";
					}//end of if($check_active)
					else
						$msg = "Please activate your account.";
				}//end of if($check_password)
				else
					$msg = "Email and password do not match.";
			}//end of of($check_email)
			else
				$msg = "User does not exist.";
		}//end of if($password)
		else
			$msg = "Enter password.";
	}//if(ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
	else
		$msg = "Enter valid email address.";
}//end of if($email)
else
	$msg = "Enter email address";

$JSON_response = '{';
$JSON_response .= '"error": "'.addslashes($error).'",';
$JSON_response .= '"fieldErrors": "'.$msg.'",';
$JSON_response .= '}';
echo $JSON_response;
?>

Link to comment
https://forums.phpfreaks.com/topic/196365-need-help-in-the-code-below/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.