Page 1 of 1
inserting into mysql field
Posted: Sat Jan 19, 2008 1:15 pm
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?
Re: inserting into mysql field
Posted: Sat Jan 19, 2008 1:38 pm
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]
Re: inserting into mysql field
Posted: Sat Jan 19, 2008 2:24 pm
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.
Re: inserting into mysql field
Posted: Sun Jan 20, 2008 1:14 am
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.
Re: inserting into mysql field
Posted: Sun Jan 20, 2008 12:21 pm
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.