Вопрос

So I have this SQL query and when I connect the php and MySQL it works but then when I try to run it, the query has an error saying it's using the wrong username/password. But the only place I entered the username and password was when connecting, and then I used the right information and it worked? Here is the code and the error:

<?php
 $con = mysqli_connect("Correct Host","Correct Username","Correct Password","Correct Database");
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

mysql_query("SELECT username, email from Profiles");
mysqli_close($con);
?>

Error:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'wronguser'@'wronghost' (using password: NO) in /home/username/public_html/register.php on line 8

Это было полезно?

Решение 3

You've used MySQLi to connect to the database but you used MySQL to run the query. Take note, in PHP, MySQL and MySQLi are different. MySQLi is the newer and improved version of MySQL. So use mysqli_query() instead of mysql_query since you've connected to the database using MySQLi.

Hope this helps!

Другие советы

You're using the wrong function to query. You connected via mysqli but then you try and query with mysql. Change your code to:

mysqli_query($con, "SELECT username, email from Profiles");

You can't switch from mysqli_* extension to mysql_* like that. Use mysqli_query.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top