Forum Moderators: coopster
Database error: Access denied for user: '@localhost' to database 'testdatabase'
Does anyone know how I can fix it?
Here's the code for my PHP page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>MySQL Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h3> Press RELOAD to add a record to the MySQL database:</h3>
<?
//establish user connection
mysql_connect("localhost");
//open up database
mysql_create_db("testdatabase");
mysql_select_db("testdatabase") or die ('Database error: ' . mysql_error());
//create table
mysql_query("CREATE TABLE newone(firstName VARCHAR(25),lastName VARCHAR(25))");
mysql_query ("INSERT INTO newone (firstName, lastName) VALUES ('Amir', 'Khan')");
//display the information
$result = mysql_query ("SELECT * FROM newone");
while($row = mysql_fetch_array($result))
{
print ("Added record: " . $row["firstName"]." ".$row["lastName"]." <br>\n");
}
//close user connection
mysql_close();
?>
</body>
</html>
<?php
$link = mysql_connect('localhost', '', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Another helpful tool is phpMyAdmin [phpmyadmin.net]