I am having a problem with the execution of this particular php page. I'm using a wamp 2 server on windows7. The output is always "Unable to Open Database", no matter what changes I make to the code. Please help! I am a newbie in php!
The php code is as follows-
<?php
//initilaize the mysql user name and password
$username="localhost";
$pwd="12345";
//database name
$database="project";
//get the information from login form
$username=$_POST['adminname'];
$pwd=$_POST['adminpwd'];
//connect the mysql database
$link=@mysql_connect("localhost","root","");
@mysql_select_db($database,$link) or die("Unable to Open Database");
//execute the query
$sql ="SELECT * FROM administrator";
$result = mysql_query($sql,$link);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if($row['vid']==$username && $row['pwd']==$pwd)
{
$flag =1;
break;
}
}
if($flag == 1)
{
header("Location:http://localhost/project/Loginmodule/adminmenu.html");
}
else
{
echo "You Are an Unauthorised User";
}
mysql_free_result($result);
mysql_close($link);
?>
The HTML source code is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
function funcval()
{
if(document.adminlogin.adminname.value==" ")
{
alert("Please provide all the required details");
}
if(document.adminlogin.adminpwd.value==" ")
{
alert("Please provide all the required details");
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Administrator Login to the Voting System</title>
</head>
<body>
<form name ="adminlogin" action="loginconnect1.php" method ="POST">
<BR><BR><center>
<H1><FONT SIZE=+7>ENTER YOUR LOGIN</H1>
<HR WIDTH=700>
<BR><BR>
<table>
<tr>
<td><FONT SIZE=+2>LOGIN </td>
<td WIDTH=300 ALIGN="CENTER"><input type="text" name="adminname"></td>
</tr>
<tr>
<td><FONT SIZE=+2>PASSWORD<SUP><FONT COLOR=RED> *</FONT></SUP> </td>
<td WIDTH=300 ALIGN="CENTER"><input type="PASSWORD" name="adminpwd"></td>
</tr>
<TR><TD></TD></TR>
<TR><TD></TD></TR>
<TR><TD></TD></TR>
<TR><TD></TD></TR>
<TR><TD></TD></TR>
<TR><TD></TD></TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE="SUBMIT" NAME="BUTTON1" VALUE="SUBMIT" ONCLICK="funcval()"></TD>
<TD ALIGN="CENTER"><INPUT TYPE="RESET" NAME="BUTTON2" VALUE="REFRESH"></TD></TR>
</TABLE>
</center>
<bR>
</form>
<bR>
<bR>
<ADDRESS><font size=+1 color=red>* : Mandatory Field</address>