I'm trying to create a very simple create account page. This is the part of the MySQL Database connection:
<?php
function dbconnect()
{
$connection = mysqli_connect("localhost","maistral_quizonline","maistral_kalkas","abcdefghi");
if (mysqli_connect_errno($connection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return 0;
}
return $connection;
}?>
When I try to run dbconnect this is what I get as output:
"Failed to connect to MySQL: Access denied for user 'maistral_quizonl'#'localhost' (using password: YES)Access denied for user 'maistral'#'localhost' (using password: NO)"
Now, I'm new to php and maybe i do something really silly, can anyone explain to me this output? Why it seems to try for connection twice and why the connection information is corrupted? What is this: maistral_quizonl? maistral? Why is it cutting the words? And why the first time says that I'm using password and the second time says no? I hope my mistake is not so stupid.
And one other thing. I saw in another post someone suggesting to check if the mysqli_connect function exists so I change this:
echo "Failed to connect to MySQL: " . mysqli_connect_error();
to this:
echo "Failed to connect to MySQL: " . mysqli_connect_error() . var_dump(function_exists('mysqli_connect'));
and the output was this:
"bool(true) Failed to connect to MySQL: Access denied for user 'maistral_quizonl'#'localhost' (using password: YES)Access denied for user 'maistral'#'localhost' (using password: NO)"
lol?
I know that it's pointless to check if mysqli_connect exists after you use it but am I mistaken or isn't the "bool(true)" suppose to print at the and of the line and not the beggining?
What is going on?
Thank you
PS: I have double check that the database exists as well as the user and the priviliges and the password
mysqli_connect accepts parameters in this order 'host', 'username', 'password', and 'dbname', is this the order in which you have provided your details? It does not seem so.
http://us2.php.net/manual/en/mysqli.construct.php
Related
I am trying to install my php script on live server but am getting an error. I have already created a db/user and uploaded sql to my phypmyadmin
Error I am getting is
Access denied for user 'user'#'localhost' (using password: YES)
It's simply telling you that the username or password is not right, so you can't have an access.
Please check the password and the name of the user inside your php script, take a look at this.
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
You see in your case you need to change these parameters to the ones in your live server.
$con = mysqli_connect("your_server","your_user","your_password","your_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
I am working on php at the moment and I am having problem with connecting to a server data base I am using MAMP
this is my code
<?php
$con = mysqli_connect('localhost','root','root','something');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
echo "string";
}
?>
I really hope you help me in my learning process
this is the error massage I got
Failed to connect to MySQL: Unknown database 'something'
Are you sure your password is "root"? If you're using WAMP (as suggested by localhost), the default password for mysql is "" (blank).
I think you have changed the localhost name as demo..and by default localhost username and password is root and ``(no-passsword)..So just try it..
$con = mysqli_connect('demo','root','','something');
I have a login script, PHP based. when I run the page I get the following error:
Access denied for user 'usernameI'#'mydomainname.com' (using password: YES)
I've confirmed my password and that the respective user has all rights to the database. I tested a small connection script and get the same error. Here is the code:
<?php
$con = mysqli_connect("mydomainname.com","usernameI","mypassword");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
...I have the above within the body tag of the PHP page. Could I get some help as to what I'm doing wrong or if there is something I've overlooked or need to confirm? Thanks!
I tried using this code to input data from a form into a database, but the code will not work and it keeps giving me access denied and error messages.I will submit my php code and a screen shot of the error messages in the hopes that you can find out why this dose not work.
Code & Screen Shot Below:
<?php
// Create connection
$con=mysqli_connect("<host>","<username>","<password>","<database>");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO usertb (username, password)
VALUES
('$_POST[username]','$_POST[password]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
Access denied would point to a DB connection error. Without seeing the error message I would say its one of two possibilities, db user being denied a connection to the DB or the user not having enough rights on the DB to be able to make changes.
Confirm that you can log into the DB with the user information you have put in you code.
mysql -D 'db name' -u 'user' -p
If you can get in OK, see if your INSERT query works at the mysql command line. If it does then you know your user can enter data into that DB and you know your query is properly formed.
If the above works all OK, then you know there is something wrong with your PHP code.
Lastly I would put a positive response on your connect and query code.
$con=mysqli_connect("<host>","<username>","<password>","<database>");
// Check connection
if (!$con)
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "Connected to DB successfully!<br>!";
}
Hopefully that gets you a little closer.
S
I want to connect 2 diffrent DB, but I get that error:
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user '*username*'#'localhost' (using password: YES) in......
my code:
$mysqli2 = new mysqli('localhost',$db_user,$db_pass, $db_name);
$mysqli2 = new mysqli('localhost',$db_user2,$db_pass2, $db_name2);
And I try to excute queries like this:
$result=$mysqli->query("select ......
$result=$mysqli2->query("select ......
How can I fix this?
Your username or password is wrong.
Your mysql user may not have the right privileges to connect over the network.
See here : How to grant remote access permissions to mysql server for user?
check password and adress and username
use next code to connect
$connect1 = new mysqli(...);
$connect2 = new mysqli()
if ($connect1->connect_error)
echo "error in 1 connection message: " . $connect1->connect_error;
if ($connect2->connect_error)
echo "error in 2 connection message: " . $connect2->connect_error;
where you see a problem ?