Warning: mysqli_connect(): (28000/1045): Access denied for user [duplicate] - php

This question already has answers here:
MySQLI 28000/1045 Access denied for user 'root'#'localhost'
(2 answers)
Closed 6 years ago.
i uploaded my php config code to my server befirstw on cpanel ...under the public html ..
my php file is
<?php
$dbhost = "befirstwin.com";
$dbname = "befirstw_intlgent";
$dbuser = "befirstw_intelli";
$dbpass = "Ngcp1988$ ";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(mysqli_connect_errno())
{
die("database connection failed: " .
mysql_connect_error() . "(" . mysql_connect_errno() .")"
);
}
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$query = "INSERT INTO users
VALUES ('', '$username', '$password')";
$result = mysqli_query($connection,$query);
if(!$result)
{
die("we have problem");
}
mysqli_close($connection);
?>
i am getting this error
Warning: mysqli_connect(): (28000/1045): Access denied for user 'befirstw_intelli'#'s147.adk-media.com' (using password: YES) in /home/befirstw/public_html/connectimagedb.php on line 8
if you have any idea or any thing more required for php connectivity plz suggest

I check that $ sign in the password is creating problem in my case.Please Do not use $ or any other special Character that may create problem. In my case $ sign in password was creating problem

This could simply be caused by an incorrect password. In your $dbpass, is the space at the end supposed to be there? That extra space before the close " would add a space to the end of the password, causing it to be a different password.

I am wondering if you are opening a connection. I notice the line, where it is closing a connection but not sure if you have opened a connection? Where is is your execute statement for the Insert Query?
Thanks

Related

Warning: mysqli_connect(): (HY000/1045): Access denied for user '$username'#'localhost' (using password: YES) in .php file [duplicate]

This question already has answers here:
What is the difference between single-quoted and double-quoted strings in PHP?
(7 answers)
Closed 3 years ago.
I'm new to php ,trying to solve my issue(connecting with database at line 12) over here please help...!!
seen similar questions over here but they haven't helped me..!!
my code is as follows:
<?php
session_start();
// variable declaration
$username = "";
$password ="";
$db='register';
// connect to database
$db = mysqli_connect('localhost', '$username','$password', 'register') or die("unable to connect");
?>
The problem is with your quotes. Single quotes ’ don’t expand variables so the username is sent as $username as the error shows. You need double quotes to expand, or in this case no quotes because you just want to pass the values from the variables:
$db = mysqli_connect('localhost', $username, $password, 'register') or die("unable to connect");

Warning: mysqli_connect(): (HY000/1045): Access denied for user 'usr'#'localhost' (using password: YES)

Warning: mysqli_connect(): (HY000/1045): Access denied for user
'usr'#'localhost' (using password: YES) in
/storage/emulated/0/htdocs/includes/condb.php on line 9 Failed to
connect to MySql: Access denied for user 'usr'#'localhost' (using
password: YES) Warning: mysqli_query() expects parameter 1 to be
mysqli, boolean given in /storage/emulated/0/htdocs/includes/condb.php
on line 19
Warning: mysqli_error() expects parameter 1 to be mysqli, boolean
given in /storage/emulated/0/htdocs/includes/condb.php on line 20
Unable to connect
Im trying to connect to the database using this code but im an unable to. I dont know what i actually did wrong. Ive tried googling and reading some articles but none of those work.
UPDATED CODE still getting the error message above.
$server = "127.0.0.1"; $username = "usr"; $password = "123"; $database
= "contents";
$conn = mysqli_connect($server,$username,$password,$database);
if(mysqli_connect_errno($conn)) {
echo "Failed to connect to MySql: ".mysqli_connect_error(); }
$sql = "INSERT INTO contents('subj','article','day') VALUES
('".$_POST['This is the subj']."', '".$_POST['This is the
content']."', '".$_POST['2019-02-01 10:15:59']."')";
if(!mysqli_query($conn,$sql)) {
die("Unable to connect".mysqli_error($conn)); }else {
echo "Connected"; }
?>
Still getting the same error above unfortunately it was not a typo error. Still couldn't get the solution to this problem it has been days. Can someone with problem solving skills help me.
You don't have to pass $conn inside mysqli_connect_errno()
remove $conn
$conn = mysqli_connect($server,$username,$password,$database);
if(mysqli_connect_errno()) {
echo "Failed to connect to MySql: ".mysqli_connect_error();
}
You can fix this error by changing your mysql username and password. There are many tutorials for changing mysql user and password with a little search

Access denied for user ''#'localhost' (using password: NO) - php [duplicate]

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 5 years ago.
I am getting this error:
Access denied for user ''#'localhost' (using password: NO)
The code passes the mysqli_connect but fails on mysql_select_db($db);
below is my code:
$conn = mysqli_connect($host,'segokaku_user','SegokakuDB',$db);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_selected = mysql_select_db($db);
if (!$db_selected) {
echo 'Can\'t use database : ' . mysql_error();
}
Use
mysqli_select_db($conn, $db)
instead
mysql_select_db($db)
I think it should solve your problem

Having issues with my database? I am trying to have a section in my site where you can add a new neighborhood?

I am trying to add a section in my site where you can fill out a small form and it will add the neighborhood in for you. When I try to fill in the form and add the new neighborhood, I get the error below. Please let me know what I am doing wrong and why I can't get these to be added into the database? Thanks for any help!
Code:
require_once('db.php');
//set the registration variables
$name = addslashes($_POST['name']);
$builder = addslashes($_POST['builder']);
$builderURL = $_POST['builderURL'];
//connect to database
$link = mysql_connect($dbhost, $dbuser, $dbpwd);
if (!$link) {
die(strip_tags('Could not connect: '.mysql_error()));
}
//add this contest to the database
$stmt = "INSERT INTO hf_neighborhoods (name, builder, builder_url, created_on) VALUES " .
"('$name', '$builder', '$builderURL', NOW())";
$result = mysql_query($dbname, $stmt);
if(!$result){
die(strip_tags('Error Adding Neighborhood: '.mysql_error()));
}
//if we made it this far, return a success
echo 'success';
?>
DB Call:
<?php
$dbhost = 'localhost';
$dbname = 'delsur_2011_dev';
$dbuser = 'delsur2011';
$dbpwd = 'newsite!';
?>
Error:
<br />
<b>Warning</b>: mysql_query() expects parameter 2 to be resource, string given in <b>/var/www/vhosts/delsurliving.com/httpdocs/hf/php/addNeighborhood.php</b> on line <b>21</b><br />
Error Adding Neighborhood:
Now I am receiving this error when I try to change it to that new code? Is it just not connecting to the database at all now? I am lost, I wasn't the one that set this file up, I was just told to go and try to fix it so that is what I am trying to do now? Thanks for your help
Warning: mysql_real_escape_string(): Access denied for user 'apache'#'localhost' (using password: NO) in /var/www/vhosts/delsurliving.com/httpdocs/hf/php/addNeighborhood.php on line 8
Warning: mysql_real_escape_string(): A link to the server could not be established in /var/www/vhosts/delsurliving.com/httpdocs/hf/php/addNeighborhood.php on line 8
Warning: mysql_real_escape_string(): Access denied for user 'apache'#'localhost' (using password: NO) in /var/www/vhosts/delsurliving.com/httpdocs/hf/php/addNeighborhood.php on line 9
Warning: mysql_real_escape_string(): A link to the server could not be established in /var/www/vhosts/delsurliving.com/httpdocs/hf/php/addNeighborhood.php on line 9
Error Adding Neighborhood: No database selected
You have to change
$result = mysql_query($dbname, $stmt);
with
$result = mysql_query($stmt, $link);
However, using mysql_* functions is deprecated and its now considered a bad practice.
Instead you should be using PDO or MySQLi!
And, dont use addslashes, at least use mysql_real_escape_string
EDIT: You should be calling mysql_real_escape_String() after you connect to the database, and not before. And also, dont forget to call mysql_select_db()!
//connect to database
$link = mysql_connect($dbhost, $dbuser, $dbpwd);
if (!$link) {
die(strip_tags('Could not connect: '.mysql_error()));
}
mysql_select_db($dbname, $link);
// Sanitize your input at least!
$name = mysql_real_escape_string($_POST['name'], $link);
$builder = mysql_real_escape_string($_POST['builder'], $link);
$builderUrl = mysql_real_escape_string($_POST['builderUrl'], $link);
//add this contest to the database
$stmt = "INSERT INTO hf_neighborhoods (name, builder, builder_url, created_on) VALUES " .
"('$name', '$builder', '$builderURL', NOW())";
$result = mysql_query($stmt, $link);
...
...
...

Access denied for user ''#'localhost' (using password: NO) [duplicate]

This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 4 years ago.
Attempting to connect to localhost sql db using the following code (Not doing anything with query at this point just want the query to execute):
<?php
$host = "localhost";
$port = 3306;
$socket = "";
$user = "root";
$password = "Password1";
$dbname = "CIIP_WIKI";
$con = new mysqli($host, $user, $password, $dbname, $port);
if(!$con)
{
echo ("db connection failed!");
die ('Could not connect to the database server' . mysqli_connect_error());
}
else {
echo ("db connection established.");
echo ("<br/>");
}
$query = sprintf("SELECT first_name FROM actor WHERE actor_id='1'");
$result = mysql_query($query);
$con->close();
?>
I keep getting the following...
Welcome
db connection established.
Warning: mysql_query(): Access denied for user ''#'localhost' (using password: NO) in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31
Warning: mysql_query(): A link to the server could not be established in C:\Program Files (x86)\EasyPHP-12.1\www\Cisco Wiki\index.php on line 31
Why does this not work?
This is because you create a connection using mysqli_ and then use mysql_ to try to fetch your result. They are different API's.
<?php
/* You should enable error reporting for mysqli before attempting to make a connection */
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
/* Set the desired charset after establishing a connection */
mysqli_set_charset($mysqli, 'utf8mb4');
printf("Success... %s\n", mysqli_get_host_info($mysqli));
Example taken from the PHP manual
This warning will be logged anytime you try to execute a query without a valid connection object being available.
In your case you thought you had a valid connection object available, but you created it using mysqli while your query is being executed using mysql. Those are two different APIs and so the mysql_query function was looking for a mysql connection object and didn't find it.

Categories