473,379 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

form validation

form validation using PHP + MYSQL + AJAX
Dec 5 '06 #1
3 1335
ronverdonk
4,258 Expert 4TB
So what??

Ronald :cool:
Dec 5 '06 #2
Hai Using This code Form validation PHP+Mysql+Javascript
[php]
home.php
<SCRIPT language="javascript" type="text/javascript">

// Set path to PHP script
var phpscript = 'login.php';

function createRequestObject() {

var req;

if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
}

return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();


function sendRequestPost() {

var user =document.getElementById('username').value;
var pass = document.getElementById('password').value;

if(user=='')
{
alert("Enter the User Name Please");
document.regform.username.focus();
return false;
}
if(pass=='')
{
alert("Enter the Password");
document.regform.password.focus();
return false;
}


var but= document.getElementById('submit');
// Open PHP script for requests
http.open('post', phpscript);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.onreadystatechange = handleResponsePost;
http.send('username='+ user +'&password='+ pass);
but.value = "please wait...";
but.disabled = true;
return true;


}


function handleResponsePost() {
var but= document.getElementById('submit');
if(http.readyState == 1){
document.getElementById("response").innerHTML = "Please wait, loading... <img src=images.jpg align=middle>" ;
} else if(http.readyState == 4 && http.status == 200){

// Text returned from PHP script
var response = http.responseText;

if(response) {
// Update ajaxTest2 content
document.getElementById("response").innerHTML = response;
but.value = "Login";
but.disabled = false;
//alert(response);
}

}
}
/*function sub(event)
{

if(event.keyCode==13)
{
var user = document.getElementById('username').value;
var pass = document.getElementById('password').value;
if(user=="")
{
alert("Enter user name");
return false;
}
if(pass=="")
{

alert("Enter password");
return false;
}
}
}*/
</SCRIPT>
<META content="MSHTML 6.00.2800.1528" name="GENERATOR"></HEAD>
<BODY>
<form method="post" name="regform" action="">
<div id="all">
<p>Username:<br>
<input name="username" type="text" id="username">
<p>Password:<br>
<input name="password" type="password" id="password">
</p>
<p>
</div>
<input name="submit" type="button" value=click onclick="return sendRequestPost()";>
</p>
</form>
<DIV id="response"></DIV>
<BR>
<br>
</BODY>
</HTML>

Login.php

<?php
session_start();
include ('config.php');

$username = $_POST['username'];
$password = md5($_POST['password']);
$querys="SELECT * FROM users WHERE user='". $username ."' AND pass='". $password ."'";
$query = mysql_query($querys);
$result = mysql_num_rows($query);
$row = mysql_fetch_array($query);

if ($result == 1)
{
$_SESSION["user"] = $row["user"];

echo 'Logged in, '. $row["user"];
}
else
{
echo 'Wrong username or password.';
}

?>
[/php]
Dec 5 '06 #3
ronverdonk
4,258 Expert 4TB
KRANTHI: I'd like to remind you that this is not a code factory!

The goal of this forum is to have members help other members. But that means that the ones seeking advice must also do what they can to accomodate the ones that want to help them. You should read the Posting Guidelines sometime.

And a statement like the one you show in your first post in this thread looks more like a command-to-deliver then a request for help. The usual procedure is that you show what you have done yourself to get to a solution, so we can all learn from it. Not by demanding.

And when other members like to be commandeered around, that is up to them, but I would like to have a civilised exchange of ideas and suggestions. Dumping code without any comment, guidance or explanation is not in that realm.

Ronald :cool:
Dec 5 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.