INSERT query help....

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Exodus00
Forum Newbie
Posts: 13
Joined: Mon Aug 05, 2002 11:46 pm
Location: Oregon
Contact:

INSERT query help....

Post by Exodus00 »

I've been making a control panel for my web site to make it really easy to update, and on one database(this page is for a lan party website) it tells whether people have payed or not. its Table registered, with the column payed, and payed either = "Y" or it = "" now this one thing I've been trying to do is to basically insert Y into the "" but only for a certain person. I have each person sorted using usernumber(an auto_increment value)..

heres the code.. I've been working on this for a while.. cant figure out what I'm doing wrong..

Code: Select all

$value = "Y";
		# setup SQL statement
		$SQL = " INSERT INTO registered WHERE usernumber = $namenumber ";
		$SQL = $SQL . " ( payed ) VALUES ";
		$SQL = $SQL . " ('$value') ";
now $namenumber was from the previous confirmation page(confirming you want to select that person.. basically a stored variable, I was trying to give a simpler name)

so basically what I wanted it to do, is.. insert into table registered only in the row where the usernumber I have selected is present, then modify column payed, by inserting value Y..... anything wrong with that you can see?.... any questions, ask, and I'll answer.. thanx for helping



edit : forgot to post the error it gave.. here it is

You have an error in your SQL syntax near 'WHERE usernumber = ( payed ) VALUES ('Y') ' at line 1 INSERT INTO registered WHERE usernumber = ( payed ) VALUES ('Y')
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post by phpPete »

You're WHERE clause is in the wrong place.

INSERT into (field1, field2...) VALUES( value1 value2...) WHERE.....
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Basically you're using the wrong type of query. If you look in the documentation on INSERT:
mysql docs wrote:INSERT inserts new rows into an existing table.
To make changes to existing rows in a database you need to use UPDATE:
mysql docs wrote:UPDATE updates columns in existing table rows with new values.
So your SQL statement would look something like:

Code: Select all

$sql = "UPDATE registered SET payed = 'Y' WHERE usernumber = '$namenumber'";
Hope it helps,

Mac
Exodus00
Forum Newbie
Posts: 13
Joined: Mon Aug 05, 2002 11:46 pm
Location: Oregon
Contact:

Post by Exodus00 »

ok now it works, but it doesn't work lol...

its.. finishing the SQL... but, its not putting a Y in the cell on the table.....

might be something with the usernumber thing.... gonna look into this.... i'll edit this post in a sec
Post Reply