Hey, well I got this query and it keeps saying mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource I can't figure out what's wrong, could anyone gimme a hand?\ <?if ((isset($_GET['action'])) && ($_GET['action'] == "updatesettings")) { $newpass = mysql_real_escape_string($_POST['newpassword']); $newpassmd5 = md5($newpass); $query ="UPDATE settings SET value='".$newpass."' WHERE name= 'admin_password'"; $result = mysql_query($query); if (mysql_affected_rows()>0) { echo "<font color=\"#00CC00\">Password Updated</font><br/>"; } else { echo "<font color=\"#FF0000\">Password Update Failed</font><br/>"; } $query ="UPDATE settings SET value='".$newpassmd5."' WHERE name= 'admin_password_md5'"; $result = mysql_query($query); if (mysql_affected_rows()>0) { echo "<font color=\"#00CC00\">Password Updated</font><br/>"; } else { echo "<font color=\"#FF0000\">Password Update Failed</font><br/>"; } } ?> PHP: But I'm pretty sure the queries getting through and changing the password. Thanks
Sounds like you have an error in your query or you've not connected to the database properly. Straight after the query run the mysql_error() and see what it produces
I could be wrong, but I didn't think you needed to concatenate your query like that. Shouldn't it just be: $query ="UPDATE settings SET value='$newpass' WHERE name= 'admin_password'"; Code (markup):
I have connected to the db, and I had modified it to set the db connection into variables and asigned an argument to mysql_affected_rows() and it didn't change anything.
<?php $connection = mysql_connect("localhost", "root", "password") or die(mysql_error()); $database = mysql_select_db("sample") or die(mysql_error()); $query = mysql_query("UPDATE users SET password='sample' WHERE id=1") or die(mysql_error()); if (mysql_affected_rows($connection) == 0) { echo "Nothing updated!"; } else { echo "Updated: " . mysql_affected_rows($connection); } ?> PHP: Works just fine - executed it 2 times .. Updated: 1 changed to Nothing updated!. Are you sure you have a connection ?