inserting into mysql field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harisp
Forum Newbie
Posts: 2
Joined: Sat Jan 19, 2008 1:06 pm

inserting into mysql field

Post by harisp »

This may sound very easy, but it's bugging me that I can't figure it out. I'm pretty decent with C++, but kinda rough with php.

I have a set called signup and a table called points. I'm trying to add to the table points, but for only a specific username. With the code I have it adds to points but to all users.

Code: Select all

$sql="UPDATE signup SET points = 'points + 30'";
What am I doing wrong and how can I get it to work right?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: inserting into mysql field

Post by VladSun »

If this query was syntaxly right, it would update all users.
[sql]UPDATE signup SET points = points + 30 WHERE user_id = $id[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
harisp
Forum Newbie
Posts: 2
Joined: Sat Jan 19, 2008 1:06 pm

Re: inserting into mysql field

Post by harisp »

this is the code that I put in:

Code: Select all

$sql="UPDATE signup SET points = points + 30 WHERE UID=$_SESSION[UID]";
but it does not update the points set at all now.
User avatar
crystal ship
Forum Commoner
Posts: 36
Joined: Wed Aug 29, 2007 5:45 am

Re: inserting into mysql field

Post by crystal ship »

harisp wrote:this is the code that I put in:

Code: Select all

$sql="UPDATE signup SET points = points + 30 WHERE UID=$_SESSION[UID]";
but it does not update the points set at all now.
Here, it seems that either in the table signup there is no column named UID or $_SESSION[UID] has no value. Make sure that the both exists else the code should work.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: inserting into mysql field

Post by califdon »

harisp wrote:This may sound very easy, but it's bugging me that I can't figure it out. I'm pretty decent with C++, but kinda rough with php.

I have a set called signup and a table called points. I'm trying to add to the table points, but for only a specific username. With the code I have it adds to points but to all users.

Code: Select all

$sql="UPDATE signup SET points = 'points + 30'";
What am I doing wrong and how can I get it to work right?
You really need to study how SQL works. To start off with, your table is named signup, not points, which is the name of the field. "Set" is merely a part of the SQL command. Next, by not using a WHERE clause, you are telling it to update every row in the table. If you are working with a real, live database, you are risking the content of all your data by trying to use SQL without understanding its syntax.
Post Reply