20.11.2013, 22:05
If you have auto increment set for your ID in your database then every entry should increment itself automatically. I always set the ID to primary as well. What "Error ID: 1062, Duplicate entry '2' for key 'PRIMARY'" means is that you are trying to insert something in a row that has data already. If you want to update a row then use the UPDATE statement and use it carefully because if you write the query wrong and execute it, it will mess up your whole table.
Here's how to update a busy row:
That would update the amount of potatoes to 10 in the first row. The table would be groceries, "Potatoes" in this case would be a column.
Also make sure to escape everything so you don't get your database injected. I like to think of the sea battle game or Microsoft Excel when I work with SQL queries.
Here's how to update a busy row:
pawn Код:
new query[128];
format(query, sizeof(query),"UPDATE `groceries` SET `potatoes` = 10 WHERE ID = 1");
mysql_query(query);
Also make sure to escape everything so you don't get your database injected. I like to think of the sea battle game or Microsoft Excel when I work with SQL queries.