Page 1 of 1

INSERT query help....

Posted: Sun Aug 18, 2002 4:10 pm
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')

Posted: Sun Aug 18, 2002 5:32 pm
by phpPete
You're WHERE clause is in the wrong place.

INSERT into (field1, field2...) VALUES( value1 value2...) WHERE.....

Posted: Sun Aug 18, 2002 5:34 pm
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

Posted: Sun Aug 18, 2002 5:55 pm
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