KnottyAlder Posted May 10, 2007 Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/ Share on other sites More sharing options...
genericnumber1 Posted May 10, 2007 Share Posted May 10, 2007 it's probably your call to mysql_connect() in mysql_connect.php... you probably didn't set a password when the username knottyalder requires one.... that's what the error message says at least, though I'm sure you can read Quote Link to comment https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/#findComment-249919 Share on other sites More sharing options...
KnottyAlder Posted May 10, 2007 Author Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/#findComment-249920 Share on other sites More sharing options...
KnottyAlder Posted May 10, 2007 Author Share Posted May 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/#findComment-249922 Share on other sites More sharing options...
genericnumber1 Posted May 10, 2007 Share Posted May 10, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/50825-solved-update-mysql-database/#findComment-250005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.