Problem with Database connection!


#1

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:

Administrator Login to the Voting System

ENTER YOUR LOGIN




LOGIN
PASSWORD *



* : Mandatory Field

#2

$link=@mysql_connect(“localhost”,“root”,"");

your DB is configured with root user and no password?

by the way, are you trying to make an authentication system? you should try PEAR. The code will be mucb more secure and robust.