Jump to content

[SOLVED] Update MySQL Database


KnottyAlder

Recommended Posts

I'm trying to update a database with a simple update query. Here's my code.

 

// Connect to the database.
require_once ('../mysql_connect.php');
echo 'Connected to database.';

// Set up the query.
$query = "UPDATE quotes SET approved=1 WHERE quote_id=$id";
echo "Query: " . $query;

// Run the query.
$results = @mysql_query ($query);
if ($results)
    echo 'Query successful.';
else
    echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';

 

I keep getting the same error: Access denied for user 'knottyalder'@'localhost' (using password: NO)

 

Any help you could offer would be greatly apprciated.

Link to comment
https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/
Share on other sites

That's what has me so confused. It has a password and it works. I have several other pages that access the same database and the same table. They work perfectly. It's just his page where I'm trying to update the information that has me in a slump.

I figured it out, but I have a question about my solution if anyone has a minute. I accessed the database twice on this same page (I pulled a bunch of results and then I'm updating them). I closed the database connection after I pulled the results and then tried to reopen it when I was updating them. Why would this cause a problem? Once I took out the mysql_close() function it worked fine.

yes, if you call the exact same connection function with the same parameters as a connection that is already open it will just use that one instead of creating a new one. That would be why, if you didn't do mysql_close(), it would use the working session...

 

I couldn't tell you why it doesn't work the second time... but why connect to the server, disconnect, then connect again anyway?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.