Hi. I wanted to make a page that I can update a table in a database. But for some reason, I get this error:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'a1092592'@'localhost' (using password: NO) in /home/a1092592/public_html/folder/file.php on line 10
and this error:
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a1092592/public_html/folder/file.php on line 10.

Here's the file that gave me this error:

<?php
session_start();

if (!session_is_registered("auth")) {

// Send that invader back home. Nothing for that person to see here.
header( 'Location: http://mywebsite.com' );
}

$host="sqlserver.hostname.com"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="database name"; // Database name 
$tbl_name="table"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<form action="url" method="POST">
<input type="submit" value="Logout" />
</form>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>

<tr>
<td align="center"><strong>Username</strong></td>
<td align="center"><strong>Banned Status</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['username']; ?></td>
<td><? echo $rows['banned']; ?></td>


// link to update.php and send value of id 
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

And this script processes what the above script sends to it:

<?php
$host="sqlserver.hostname.com"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="database name"; // Database name 
$tbl_name="table"; // Table name

// update data in mysql database 
$sql="UPDATE $tbl_name SET username='$username', password='$lastname', email='$email', banned='$banned' WHERE id='$id'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<br />";
echo "<a href='mywebsite.com/folder/files.php'>View result</a>";
}

else {
echo "ERROR";
}
?>

These files have something to do with the error. I don't know why the first error occurred. I was not using localhost, I was using my SQL server of my host. The other error I don't know how it cannot connect to the server when I gave very good detail of the SQL server to my script.

Thanks if you help.

Recommended Answers

All 2 Replies

From the MySSQL documentation:
The Access denied error message tells you who you are trying to log in as, the client host from which you are trying to connect, and whether you were using a password. Normally, you should have one row in the user table that exactly matches the host name and user name that were given in the error message. For example, if you get an error message that contains using password: NO, it means that you tried to log in without a password.

Servers are normally named "localhost" (including, but not limited to your local test server).

You could try removing the quotes around the variables on line 18. This may cause a problem with your other mysql statements as well.

Now it does nothing. I don't get any errors from MySQL, but it just does nothing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.