1

I am creating some login pages on Linux using PHP and MySql. It worked perfectly before. However, all of a sudden, I start to get the PHP code on a browser instead of the table that was displayed before.

I didn't change the code at all and the database and tables are still there, but when I log into MySql with mysql -r root -p, I got an error that is

'ERROR 1045 (28000): Access denied for user 'student'@'localhost' (using password: YES)' , so I have to log into MySql with sudo mysql -r root -p.

Login page (worked before):

$servername = "localhost";
$username = "phpproject";
$password = "pass";
$dbname = "ProjectDb";

// Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

Trial login page:

   define('DB_SERVER', 'localhost');
   define('DB_USERNAME', 'phpproject');
   define('DB_PASSWORD', 'pass');
   define('DB_DATABASE', 'ProjectDb');
   $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);

Does anyone have any idea what is the problem?

1

mysql -r root -p will attempt to connect to the schema root as the current user, with a password prompt, using raw output. This is probably not what you intend to be doing.

Try mysql -uphpproject -p ProjectDb. If that works, something is awry in your PHP configuration; if it does not, you have bad credentials. The answer is not to just connect as the root user; the answer is to correct your credentials.

|improve this answer|||||
  • Thank you. I could login with 'mysql -uphpproject -p ProjectDb' without the error. However, the PHP code is displayed on a browser without displaying the proper content. Does PHP configuration mean connection code? That worked before, but not anymore. How to correct my credentials? – mercredi Aug 16 '17 at 16:49
  • If going to the PHP page in a browser shows you the PHP source rather than the results of its execution, that implies that your HTTP server daemon does not have its PHP module enabled, which is beyond the scope of this question. Presuming apache, you can start with sudo a2enmod php perhaps. – DopeGhoti Aug 16 '17 at 16:52
  • Ok, Thank you so much. so my problem is not the PHP or MySql, it is Apache. That makes sense. I will try the command that you provided. Thank you! – mercredi Aug 16 '17 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.