Jump to content

Can't Add +1 to mySQL database field


shawhey

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.