Click here to Skip to main content
15,887,135 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: HTML5 Javascript Issue Pin
#realJSOP4-Dec-12 7:31
mve#realJSOP4-Dec-12 7:31 
GeneralRe: HTML5 Javascript Issue Pin
Zaf Khan19-Dec-12 20:36
Zaf Khan19-Dec-12 20:36 
AnswerRe: HTML5 Javascript Issue Pin
Zaf Khan19-Dec-12 20:42
Zaf Khan19-Dec-12 20:42 
QuestionCatching Exceptions in Javascript Pin
Ved Yo29-Nov-12 14:43
Ved Yo29-Nov-12 14:43 
QuestionPartial Overlay to cover ajax request Pin
Sentenryu29-Nov-12 1:51
Sentenryu29-Nov-12 1:51 
QuestionHow to get value from TD Pin
Chitttapa26-Nov-12 10:03
Chitttapa26-Nov-12 10:03 
Questionhelp me please Pin
nth9224-Nov-12 4:16
nth9224-Nov-12 4:16 
AnswerRe: help me please Pin
Leon Munir25-Nov-12 13:46
Leon Munir25-Nov-12 13:46 
Here is the complete code without ajax functionality. You didn't mention in the question if you wanted to display result without loading the php page.The login.html could looks like this:
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<script type = "text/javascript">

JavaScript
function validate(){
    if((f1.login.value == "") || (f1.password.value == ""))
    {
        alert("you must enter your name and password");
	return false;
    }
    else
    {    
	return true;
    }
}

HTML
</script>  
</head> 
<body>
<form  id ="f1"  action = "validate.php" method="post" onsubmit ="return validate(this);">
User Name <input  type ="text"  name = "login"/> <br />
Password <input  type ="password" name ="password"/> <br />
<input type = "submit"  value ="login"/>
</form> 
</body> 
</html>


The validate.php could look like this:

PHP
<?php
// fetching username and password
$userName = $_REQUEST["login"];
$userPassword = $_REQUEST["password"];
	
// using regular expressions to evaluate username
if(preg_match("/^[a-zA-Z][a-zA-Z0-9_]+$/", $userName, $matches)	)
{
    CheckWithDatabase($userName,$userPassword);
}
	
function CheckWithDatabase(&$usr, &$pw)
{
    // connecting to the database 
    mysql_connect("localhost", "userleon", "Pa55word") or die(mysql_error()); 
    mysql_select_db("students") or die(mysql_error()); 
    $data = mysql_query("SELECT login, password FROM login_password") or die(mysql_error());  
    while($info = mysql_fetch_array( $data )) 
    { 
         if( ($usr == $info['login']) && ( $pw == $info['password'] ))
	{
            echo "Thank you for logging in";
            // two choices offered on successful login
            echo "<form><input type=\"radio\" name=\"choice\" value=\"Add a new student\">Add a new student<br/><input type=\"radio\" name=\"choice\" value=\"Remove a student\"/>Remove a student</form>";
	}
	else
	{
            // GO BACK link
            echo "<a href=\"javascript:history.go(-1)\">GO BACK</a>";
            // javascript displays message
            echo "<script type=\"text/javascript\">alert(\"wrongpassword and/or login please try again\");</script>";
	}
    } 
}
?>


Hope it answers your question Smile | :)
follow me on twitter @leon_developer


modified 25-Nov-12 20:15pm.

GeneralRe: help me please Pin
J4amieC25-Nov-12 21:13
J4amieC25-Nov-12 21:13 
GeneralRe: help me please Pin
Leon Munir26-Nov-12 2:06
Leon Munir26-Nov-12 2:06 
GeneralRe: help me please Pin
J4amieC26-Nov-12 5:30
J4amieC26-Nov-12 5:30 
GeneralRe: help me please Pin
fjdiewornncalwe26-Nov-12 5:37
professionalfjdiewornncalwe26-Nov-12 5:37 
GeneralRe: help me please Pin
nth9226-Nov-12 9:28
nth9226-Nov-12 9:28 
Questiononmouseover and document.getElementById Pin
SRJ9223-Nov-12 4:18
SRJ9223-Nov-12 4:18 
AnswerRe: onmouseover and document.getElementById Pin
J4amieC23-Nov-12 4:48
J4amieC23-Nov-12 4:48 
GeneralRe: onmouseover and document.getElementById Pin
SRJ9223-Nov-12 5:49
SRJ9223-Nov-12 5:49 
AnswerRe: onmouseover and document.getElementById Pin
sachin_jain30-Nov-12 9:17
sachin_jain30-Nov-12 9:17 
Questiondisplaying different contentunder single layout Pin
radha123 from Hyderabad23-Nov-12 3:32
radha123 from Hyderabad23-Nov-12 3:32 
AnswerRe: displaying different contentunder single layout Pin
manojwadnere28-Dec-12 0:07
manojwadnere28-Dec-12 0:07 
QuestionRegular expression Pin
Member 962181822-Nov-12 2:25
Member 962181822-Nov-12 2:25 
AnswerRe: Regular expression Pin
n.podbielski22-Nov-12 20:00
n.podbielski22-Nov-12 20:00 
GeneralRe: Regular expression Pin
Manfred Rudolf Bihy22-Nov-12 21:20
professionalManfred Rudolf Bihy22-Nov-12 21:20 
GeneralRe: Regular expression Pin
n.podbielski23-Nov-12 21:15
n.podbielski23-Nov-12 21:15 
Questionform validation Pin
therainking7821-Nov-12 22:07
therainking7821-Nov-12 22:07 
AnswerRe: form validation Pin
Richard MacCutchan21-Nov-12 22:17
mveRichard MacCutchan21-Nov-12 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.