Newbie MySQL Question

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
cyk0
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 10:13 am

Newbie MySQL Question

Post by cyk0 »

Hello,

I know this is probably an easy question, but I don't know how to do it.
I have 4 columns; name, email, code, ip. I have one form to add rows with just the code column filled and the others left blank. How do I make another form to update those rows to add the rest (name, email, ip)?
Any ideas?

Thanks in advance.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You want to do an UPDATE query. Something like,

Code: Select all

$sql = "UPDATE table SET name='$name', email='$email', ip='$ip' WHERE code='$code'";
Where $name, $email, $ip and $code have all been passed from the second form and table is the name of the table you want to update. $sql is then the query that you would run.

Mac
cyk0
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 10:13 am

Post by cyk0 »

Thanks for that.

I have another question (sorry). Now that I know how to update rows, I want to know how to update the next row each time someone successfully signs up for a code, so each person gets a different code. Would I have to make an ID column and set it to auto_increment or something?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does the code need to look like? Can it just be a number because then you could use an auto-increment on the code column and make the code the primary key so it will also be unique for each person.

Mac
cyk0
Forum Newbie
Posts: 3
Joined: Fri Jun 14, 2002 10:13 am

Post by cyk0 »

The codes are a mixture of numbers and letters, so I don't know if that would work.
I set an id column to auto_increment so it does 0, 1, 2, etc. But I don't know how to do the code.

Thanks for any help you can give
Post Reply