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
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:
and use this to connect to your database and save it as dbconnect.php
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.