Jc23
Jc23

Reputation: 3

Can't connect MySQL table to my PHP file

I've been trying to to connect a table I created in phpmyadmin to a php file, but every time I try to access it I get this messsage:

warning: mysql_connect(): Access denied for user 'jc'@'localhost' (using password: YES) in /home/k1146376/www/lr/connect.php on line 2 Access denied for user 'jc'@'localhost' (using password: YES)

This is the code I am using to call the table:

<?php

session_start();
require_once("connect.php");
if (isset($_GET['page'])){
$pages= array("products","cart");
if(in_array($_GET['page'],$pages)){
$page = $_GET['page'];
} else {
$page = "products";
}
} else {
$page = "products";
}
?>

this is my connect file:

<?php
mysql_connect('localhost','jc','password') or die (mysql_error());
mysql_select_db('products') or die (mysql_error());
?>

Upvotes: 0

Views: 30

Answers (2)

hanshenrik
hanshenrik

Reputation: 21513

CREATE USER 'jc'@%
GRANT ALL PRIVILEGES ON *.* TO jc

check that you're using the correct username/password.

stop using mysql_* (use mysqli_ , or better yet, PDO~)

check what mysql server version is running check the relevant docs. maybe its https://dev.mysql.com/doc/refman/5.5/en/access-denied.html ?

Upvotes: 0

Patrick Reck
Patrick Reck

Reputation: 11374

Some of your login credentials in connect.php is wrong. Put in the correct informations for your database and it'll work.

If you are on your own machine, you can go to http://localhost/phpMyAdmin and pick Users in the top navigation. Here you can add a new user or edit an existing one.

You are currently trying to login with the username jc and the password password.

Upvotes: 3

Related Questions