For school I have to build and basic website using PHP and MySQL. The websites function is to allow a user to register and then sign in and out. To do this, since I have no prior knowledge of PHP I was trying to follow this tutorial. I got sever space with godaddy and using MySQL I created the database called details_db. I created the files the tutorial told me and uploaded to the server. Now when I go onto the website I get these errors.
Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 12
Warning: mysql_select_db(): Access denied for user ''@'localhost' (using password: NO) in /home/pendrive34/public_html/dbconnect.php on line 13
Warning: mysql_select_db(): A link to the server could not be established in /home/pendrive34/public_html/dbconnect.php on line 13 Connection failed : Access denied for user ''@'localhost' (using password: NO)
This is the code in the file deconnect.php
<?php
// this will avoid mysql_connect() deprecation error.
error_reporting( ~E_DEPRECATED & ~E_NOTICE );
// but I strongly suggest you to use PDO or MySQLi.
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', '');
define('DBNAME', 'details_db');
$conn = mysql_connect(DBHOST,DBUSER,DBPASS);
$dbcon = mysql_select_db(DBNAME);
if ( !$conn ) {
die("Connection failed : " . mysql_error());
}
if ( !$dbcon ) {
die("Database Connection failed : " . mysql_error());
}
I've been trying to find the answer to the problem for a while but my limited knowledge is holding me back.
mysql_
its deprecated since php 5.5.0 – Blueblazer172localhost
is incorrect, that is trying to access your local system. – chris85