Help on the bugs

joejoe BeginnerLink Clerk
I created a login temp and a PHP codes.

Please can anyone help to solve my problem. when I type in user name and password following error come up. My database named "test".


Warning: Access denied for user: 'username@localhost' (Using password: YES) in /home/GCO01/public_html/AS2/login.php on line 10

Warning: MySQL Connection Failed: Access denied for user: 'username@localhost' (Using password: YES) in /home/GCO01/public_html/AS2/login.php on line 10
Could not connect to mySQL:Access denied for user: 'username@localhost' (Using password: YES)


<html>
<head><title>login</title></head>
<body bgcolor=gold>
<center>
<form method=post action="login.php">
<table border=1 cellpadding=3 celspacing=3 align=center width=50%>
<tr>
<td colspan=2 align=center>Login</td></tr>
<tr>
<td colspan=2 align=center>
<?php if (isset($username)){if ($logout==false){if(isset($err)){echo "$err";}}}?></td></tr>
<tr>
<td>Username:</td><td><input type=text name=username size="20"></td></tr>
<tr>
<td>Password:</td><td><input type=password name=password size="20"></td></tr>
<td></td>
<tr>
<td><input type="reset" name="Submit2" value="Reset"></td>
<td><input type="submit" name="Submit" value="Submit"></td></tr>

</table>
</form>
</body>
</html>


//login.php//

<?php

// Connect to MySQL
$db_connect = mysql_connect(localhost, username, password) or
die('Could not connect to mySQL:'.mysql_error());

$table_name = 'Unit';

$query = 'SELECT * FROM Unit';

mysql_select_db($dbname);

$results_id = mysql_query($query, $db_connect);

if ($results_id) {

print '<table border=1>';

print '<th>UnitCode<th>UnitNmae<th>LectName';

while ($row = musql_fetch_row($results_id)) {

print '<tr>';

foreach ($row as $field) {

print "<td>$field</td>";
}
print '</tr>';
}
};
mysql_close($db_connect);
?>
</table>

Comments

  • james.ukjames.uk Junior Member Shared Hoster
    there's nothing wrong with the code. you just have to make sure all your dbconnect details are correct.

    Try this creating a single page which is dedicated to connecting to your database by creating a dbconnect.php then just simply insert this to any page where you want to include the file:
    include 'dbconnect.php';
    

    and use this to connect to your database and save it as dbconnect.php
    <?php
    
    $username = "username"; //your username
    $password = "password"; //your password
    $host = "your.host.com usually localhost"; //your mySQL server
    $database = "databasename"; //The name of the database your table is in
    
    mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error()); //connect, but if there is a problem, display an error message telling why there is a problem
    
    mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error()); //Choose the database from your mySQL server, but if there is a problem, display an error telling why
    
    ?>
    

    always works for me, just try it and see what happens. trouble is im at work at the moment so i cant find out exactly what the problem is.
    A psychopath with dyslexia
  • joejoe Beginner Link Clerk
    How do I verify the people put in username and password from login page with my database?
Sign In or Register to comment.