Connecting Tech Pros Worldwide Forums | Help | Site Map

form validation

Newbie
 
Join Date: Dec 2006
Posts: 1
#1: Dec 5 '06
form validation using PHP + MYSQL + AJAX

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Dec 5 '06

re: form validation


So what??

Ronald :cool:
Newbie
 
Join Date: Nov 2006
Posts: 17
#3: Dec 5 '06

re: form validation


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]
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Dec 5 '06

re: form validation


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:
Reply