1

I wrote some function used by a php webpage, in order to interact with a mysql database.In total I have 5 similar php pages. When I test them on my local server everything works fine. the data is populated in mysql DB. but when I host it on the web server, 3 out of my php files shows "Could not connect: Access denied for user 'root'@'localhost' (using password: YES)". whereas the other 2 files are executed as expected. I am using phpmyadmin and I'm hosting the site through cpanel. Could someone help me out with this problem?

The following is the code for one my php file that throws the error

<?php
session_start();
define ('DB_NAME', 'roze');
define('DB_USER', 'root');
define('DB_Password', 'good');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_Password);

if (!$link)
{

die('Could not connect: ' . mysql_error());

}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected)
{
    die('Cannot use' . DB_NAME . ': ' . mysql_error());
}

echo 'Connected Successfully';


$value4 = $_POST['couch_table'];



$sql = " UPDATE master set couch_table= '".$value4."'";

if (!mysql_query($sql)){
die('Error: ' . mysql_error());
}

header('location: room.html'); 

?>

Additional info: I have created my FTP and uplaoded my files through Filezilla.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • 4
    Well, we certainly cannot help you with your database server credentials. But _if_ you are using some hosting service provider, then I doubt _very_ much that you have access to the `root` account of their database server. – arkascha Nov 20 '16 at 14:24
  • 3
    Please don't use the `mysql_*` functions. They were deprecated in PHP 5.5, which is so old it no longer even receives security updates, and completely removed in PHP 7. Instead, use PDO or `mysqli_*`. See http://stackoverflow.com/q/12859942/354577 for details. – ChrisGPT was on strike Nov 20 '16 at 14:25
  • 3
    are you sure you have the same password in all files? because that error message basically tells you "your password is invalid". also: you should put your credentials in a seperate file which you then include. also: **don't** use the deprecated `mysql` functions which are removed in PHP7, use `mysqli` or `PDO` instead. and your code is horribly vulnerable to SQL injections, imagine someone posting a value like `'; DROP TABLE master -- ` - use parameterized statements to protect yourself. – Franz Gleichmann Nov 20 '16 at 14:25
  • let us see code of two your files - one which connects successfully and one which couldnt connect... I guess they have differences that would explain everything :) – AlexandrX Nov 20 '16 at 14:34
  • Sidenote: You do realize that you will update your entire table by not using a `WHERE` clause. – Funk Forty Niner Nov 20 '16 at 15:10

1 Answers1

0

Also you can try to create a new mysql user with all privileges, and then connect with that credentials.

SGh
  • 137
  • 1
  • 2
  • 9