shawhey Posted November 23, 2010 Share Posted November 23, 2010 Hi, so I have a fantasy hockey website and am trying to create an application that will allow me to add points to players in the database by clicking a button. I've tried everything I can think of, but it still doesn't work. Here is a link to the application: http://moscowhockey.1free.ws/rosterupdate.php Here is the piece of code for 'Add Goal': if (isset($_POST['AddGoal'])) { $lastname = $_POST['LastName']; $sql = mysql_query("SELECT * FROM roster WHERE LastName = '$lastname'"); $sql[Goals]+=1; // now we insert it into the database mysql_query("UPDATE roster SET Goals=$sql[Goals] WHERE LastName = '$lastname'"); } ?> Link to comment https://forums.phpfreaks.com/topic/219567-cant-add-1-to-mysql-database-field/ Share on other sites More sharing options...
trq Posted November 23, 2010 Share Posted November 23, 2010 You don't need a SELECT query, and even if you did mysql_query returns a result resource, not an array. if (isset($_POST['AddGoal'])) { mysql_query("UPDATE roster SET Goals=Goals+1 WHERE LastName = '$lastname'"); } ps: Do not use variables directly within queries like that, you are asking for trouble. Make sure you sanitize all user inputted data with mysql_real_escape_string. Link to comment https://forums.phpfreaks.com/topic/219567-cant-add-1-to-mysql-database-field/#findComment-1138364 Share on other sites More sharing options...
shawhey Posted November 23, 2010 Author Share Posted November 23, 2010 wow, I need some rest. Completely overcomplicated that whole thing. Thanks for the help and advice. I just started using php about a week ago, so I have much to learn. Link to comment https://forums.phpfreaks.com/topic/219567-cant-add-1-to-mysql-database-field/#findComment-1138367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.