Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Configure & Transfer the MySQL(with login credentials) from XAMPP local webserver to Hostgator/Linux based hosting Server?

I created this custom website which has a login page. There's no wordpress or any CMS involved. It's working fine when I run the website in the local server. I'm not really sure how to host it in a shared server despite of trying many times, and migrate the simple database I have which has 4 columns(index, username, email, password).

Errors recieved:

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: NO) in /home4/ablev3/public_html/connect.php on line 2

Database Connection FailedAccess denied for user 'root'@'localhost' (using password: NO)


Here's the code of my connect.php file:-

<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
    die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('ablev3_test');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}

What should I keep instead of 'localhost'and 'root' when I upload the file to hostgator shared server? Seems like that were im getting the error. Thanks.

Will appreciate any help.


##Attempt 2##

I tried the suggestions in the following order, still unresolved, what am I doing wrong? Please see below:

  1. I made a new database
  2. Created and added a new user and set new password for that database
  3. Linked the user to the database
  4. Changed 'root' to replace with my DB username
  5. Changed '' to my DB password

Now errors I get(when typing the domain name) looks like this:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home4/ablev3/public_html/index.php:1) in /home4/ablev3/public_html/index.php on line 2

My connect.php code, after changes:-

<?php
$connection = mysql_connect('localhost', 'MyDatabaseUsername', 'MyDatabasePassword');
if (!$connection){
    die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('NameOfMyNewDatabase');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}

My index.php code after changes:-

 <?php 
session_start();
require('connect.php');
//3. If the form is submitted or not.
//3.1 If the form is submitted
if (isset($_POST['username']) and isset($_POST['password'])){
//3.1.1 Assigning posted values to variables.
$username = $_POST['username'];
$password = $_POST['password'];
//3.1.2 Checking the values are existing in the database or not
$query = "SELECT * FROM `tableOTA` WHERE username='$username' and password='$password'";
$result = mysql_query($query) or die(mysql_error());
$count = mysql_num_rows($result);
//3.1.2 If the posted values are equal to the database values, then session will be created for the user.
if ($count == 1){
$_SESSION['username'] = $username;
}else{
//3.1.3 If the login credentials doesn't match, he will be shown with an error message.
echo "Invalid Login Credentials.";
}
}
//3.1.4 if the user is logged in Greets the user with message
if (isset($_SESSION['username'])){
header( 'Location:introduction.php' );
$username = $_SESSION['username'];
echo "Hai " . $username . "";
echo "This is the Members Area";
echo "<a href='logout.php'>Logout</a>";
}else{
//3.2 When the user visits the page first time, simple login form will be displayed.
?>
<!DOCTYPE html>
<html>
 <head>

<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
    <!-- Form for logging in the users -->
  >     <div class="register-form"> 

..............
..........
.........

What am I doing wrong? how to rectify this error?

like image 960
Able Varghese Avatar asked Jan 01 '26 23:01

Able Varghese


1 Answers

May be the Username or Password you are using is in the php code are wrong.

For Hostgator:

The mysql admin username is the username that was supplied to you by hostgator for your hostgator account.

The mysql password can be changed in Plesk under Server>Database Servers (I presume the initial password is the password given to you by hostgator for your hostgator account, but I never logged in before changing my password).

Attempt 2

Move the session_start(); to top of the page always. Before session_start() there should be no code(php/html/anything). And add @ob_start(); before session start.

               <?php
                  @ob_start();
                  session_start();
               ?>
like image 113
Manohar Gunturu Avatar answered Jan 03 '26 12:01

Manohar Gunturu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!