0
votes

Guys i'm having common issue. I want to display data from MySQL database into HTML page using PHP.

Using this code:

<html>
<head>

<title>Pulse Sensor Data </title>

</head>
<body>

<?php

$servername = 'localhost'; 
$username = 'root';  
$password = '';

// Connect to database server
mysql_connect('192.168.1.106','root','','database') or die (mysql_error ());

// Select database
mysql_select_db('database') or die(mysql_error());

// SQL query
$strSQL = "SELECT * FROM pulsesensor";

// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);

// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {

   // Write the value of the column id and value
  echo $row['id'] . " " . $row['value'] . "<br />";

  }

// Close the database connection
mysql_close();
?>

</body>
</html>

but i got

mysql_connect(): Access denied for user 'root'@'XXX' (using password: NO) in C:\xampp\htdocs\html.php on line 16 Access denied for user 'root'@'Dell' (using password: NO)

i changed the password the same error appear

mysql_connect(): Access denied for user 'root'@'XXX' (using password: YES) in C:\xampp\htdocs\html.php on line 16 Access denied for user 'root'@'Dell' (using password: YES)

i don't know what to do

2
so why did you assign this $servername = 'localhost'; and using 192.168.1.106 after?Funk Forty Niner
You need to stop using mysql_* functions. They have been deprecated for years and don't even exist in current PHP releases. Please study about PHP Data Objects, commonly referred as PDO for short.sidyll
Is 192.168.1.106 the local computer's IP address? If not, you need to grant permission to connect from your IP on the MySQL server. You should also create a user to use to connect with. Using root/administrator accounts should only be done when you actually need to.Mike
You are connecting to Dell, localhost, or 192.168.1.106?chris85

2 Answers

1
votes

Your connection string is using the ip address and root is not configured to access via the ip address you are using for the host. You will have to change it to localhost or add that permission to your mysql server for the root user.

I would suggest that you not do that, but create a new mysql user for your development.

Also, from @sidyll you will not want to use the mysql_* functions and use PDO functions instead.

-1
votes

Try this:

mysql_connect($servername,'root','','database') or die (mysql_error ());