[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Jquery php login

Posted on 2009-02-15
5
Medium Priority
?
1,299 Views
Last Modified: 2012-08-13
I was wondering if somebody can give me a login code example using jquery and php.  I have provided the login process the username is admin and the password is 123

the login process url is.  

http://www.m35117.com/school/login_repsone.php

it returns a yes or no

If the user enters a invalid password a Div will pop up and say invalid password.  If the password is correct it will redirect to another page
0
Comment
Question by:stargateatlantis
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
ali_pakkan earned 2000 total points
ID: 23646107
Hope that helps:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.form.js"></script>
<script type="text/javascript">
 
function processLogin(data) {
	if (data == "yes") {
		document.location.href = "login_success.php";
	} else {
		$("#loginresult").html("invalid username or password");
	}
}
 
$().ready(function() {
	$("#loginform").validate({
		rules: {
			username: "required",
			passwd: "required"
		},
		messages: {
			username: "Username cannot be empty",
			passwd: "Password cannot be empty"
		},
		submitHandler: function(form) {
			var options = {
				url: "login_repsone.php",
				success: processLogin
			};
			$(form).ajaxSubmit(options);
		}
	});
});
</script>
</head>
<body>
<form class="loginform" id="loginform" method="get" action="">
	<fieldset>
		<legend>Please provide username and password</legend>
		<p>
			<label for="username">Username (required)</label>
			<input type="text" id="username" name="username" />
		</p>
		<p>
			<label for="passwd">Password (required)</label>
			<input type="text" id="passwd" name="passwd" />
		</p>
		<p>
			<input class="submit" type="submit" value="Submit"/>
		</p>
		<p>
			<div id="loginresult"></div>
		</p>
	</fieldset>
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 23654848
It doesn't work at all.  When i test the form without the jquery it works.  
0
 
LVL 6

Expert Comment

by:ali_pakkan
ID: 23655228
Oops.. Doesnt work at all?

You included the library files? Are they where they are meant to be?


<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.form.js"></script>

Open in new window

0
 

Author Comment

by:stargateatlantis
ID: 23655804
Take a look


http://www.m35117.com/school/lgn.php

all the js files are uploaded as well.  
0
 
LVL 6

Expert Comment

by:ali_pakkan
ID: 23655941
i cant see any problem.. Would you please double check that the names of the parameters of the input elements and the ones you read in login_repsone.php are same.. "username", and "passwd".

And you can try to put at the beginning of login_repsone.php to trace:

echo "yes";
exit();

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month18 days, 16 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question