Hi, I just prepared a basic html code for a login page and another webpage linked to the login page.I need to connnect it with a mysql database.
But I am unable to do so.
Whathave I done is made a html code with a javascript function which is further calling the php code of the database.
When I tried running it, it should check the username and password in the database and then allow to next webpage.but it is not doing so.
Please let me know a simpler way to connect my database.
<html><head><title> My First HTML Webpage </title> <script>
function check(form)
{
if (str==" ")
{
document.getElementByPassword("txtHint").innerHTML=" ";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+ , Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{//code for IE6,IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 "xmlhttp.status==200)
{
document.getElementByPassword("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","php/db.php?q="+str,true);
xmlhttp.send();
}
</script> </head> <body> <center> <h1> <u>LOGIN FORM</u> </h1> </center> <hr /> <form> <u>USERNAME</u> <input type='text' name=username><br /> <u>PASSWORD</u> <input type='password' name=password><br /> <a href="MyWebPage2.html"><input type='button' onclick='check(this.form)' value='login'></a><br /><br /><br /> <p title=WELCOME!>Please login your information before continuing</p> </form> </body> </html>
this is my HTML code..
$host="localhost"; // Host name.
$db_user="root"; // MySQL username.
$db_password=""; // MySQL password.
$database="mydatabase"; // Database name.
$link = mysql_connect($host,$db_user,$db_password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
else
{
echo "Mysql Connected Successfully";
}
$login = mysql_query(“select * from table_name where (username = ‘” . $_POST[‘username’] . “‘) and (password = ‘” . md5($_POST[‘password’]) . “‘)”,$db);
$rowcount = mysql_num_rows($login);
if ($rowcount == 1) {
$_SESSION[‘username’] = $_POST[‘username’];
header(“Location: MyWebPage2.html”);
}
else
{
header(“Location: index.html”);
}
mysql_close($link);
?>
and this is my php code.thanks.