1

Topic: Not a prob, but a question!

Hello.

I was wondering how I could add a row to a table in the database when a user registers. I want to have 'scores' for my site, and it would be easiest to do it with another table, instead of adding on to the 'users' table. I do have the id auto incrementing, and all of the scores start at zero.

So my question is, what is the accurate code for inserting a row, and where do I put it? I looked in register.php, but I am not sure where it would go.

My current code is this:

//Insert another row for the highscores for that user
$db->query('INSERT INTO '.$db->prefix.'scores (`username`) VALUES ($username)');

But if that is correct, I must have it in the wrong spot.

Thanks for your help!

-AG

Re: Not a prob, but a question!

Moved to Integration
Do you want to add a new table or a new row?
If you want to add a new table, will a user have multiple entries in the scores table? If so, you'll want to have the auto incrementing ID and a column in the new table to store user id for lookups. If not, then ditch the auto incrementing ID and just make the user id column for the new table the primary key.

3 (edited by AG 2007-04-05 23:46)

Re: Not a prob, but a question!

New row.

And I made the 'id' the primary key to auto increment. There are multiple scores, so I need a table. The problem is, I don't know how to add a row when a user is created. I also don't know how to delete it for that matter.

4

Re: Not a prob, but a question!

Look for the line in register.php: // Add the user

The database update is below there.

Re: Not a prob, but a question!

AG wrote:

New row.

And I made the 'id' the primary key to auto increment. There are multiple scores, so I need a table. The problem is, I don't know how to add a row when a user is created. I also don't know how to delete it for that matter.

What I would do is copy a $db->query call from elsewhere (the full line) and start work with that. The way your code is set up now, you would never know if the query failed.

6

Re: Not a prob, but a question!

Yeah, I did that and got an error. Do I have to include every column of the table in the query? Maybe I have to activate NULL on the rows i dont set?

Thanks for your help!

Re: Not a prob, but a question!

You don't have to include every column. I would look at your PHP syntax because to me it looks like the query actually being executed is
INSERT INTO prefixscores (`username`) VALUES ($username)

where prefix is the database prefix

8 (edited by AG 2007-04-07 15:33)

Re: Not a prob, but a question!

It was the syntax. Thanks for all your help!

Somehow it also deletes the scores properly too, so I'm all set!