MyBB Community Forums

Full Version: Updating avatar via custom PHP form - Need help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to write a MySQL query in PHP that will update a users avatar in the mybb_users table. I planned to use a form to submit the data and a variable named $avatar to which will get inserted into the database.
I can't seem to figure out how to insert the data. I've connected to the database ok I think. Could anyone point me in the right direction or give an example query that I could use?
(2010-03-31, 09:07 PM)miimario Wrote: [ -> ]I am trying to write a MySQL query in PHP that will update a users avatar in the mybb_users table. I planned to use a form to submit the data and a variable named $avatar to which will get inserted into the database.
I can't seem to figure out how to insert the data. I've connected to the database ok I think. Could anyone point me in the right direction or give an example query that I could use?

Does anyone have any idea about how to do this? So far I have connected to my database and then I have this query.
mysql_query(UPDATE mybb_users SET avatar = '/images/mario.png' WHERE uid = '1';) or die ('Error updating database');

Right now I am trying to get it to work hardcoded. After I getting working this way I need to use variables in place of the avatar url and uid. Currently all I get is "Error updating database". I have used this query in phpMyAdmin and it works fine. Any ideas as to why it won't work in my PHP page?
Have you first connected to the database in your script using mysql_connect()?
Yes, I currently have this

mysql_connect ("localhost", "DATABASEUSER",
"DATABASEPASSWORD") or die('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("DATABASENAME");