Storing username & passwords & e-mails & gender

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

Storing username & passwords & e-mails & gender

Post by Mythic Fr0st »

When you sign up

How do I check if the username isnt taken, and the email isnt taken

then if they're both not taken store username & password & email & gender (radio button) into MySQL
me!
Forum Contributor
Posts: 133
Joined: Sat Nov 04, 2006 8:45 pm

Post by me! »

Use an "if" in your registration form validation. If its taked tell them they need to use something different.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post by Mythic Fr0st »

I know, but how do I check through MySQL, and how do I even add them to the DataBase? O_O
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Create unique indices for both fields username and email (each). Mysql will not allow the same value twice for such fields.

Code: Select all

CREATE TABLE `tablename` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `idx_username` (`username`),
  UNIQUE KEY `idx_email` (`email`)
)
instead of inserting the doublet mysql will then set the error
http://dev.mysql.com/doc/refman/5.1/en/error-messages-server.html wrote:#

Error: 1062 SQLSTATE: 23000 (ER_DUP_ENTRY)

Message: Duplicate entry '%s' for key '%s'
You can fetch the error code 1062 via mysql_errno
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

ok

Post by Mythic Fr0st »

Ok, I put the SQL stuff into the SQL section in the PHPmyadmin tab, but how do I add data to it lol?
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Re: ok

Post by hrubos »

Mythic Fr0st wrote:Ok, I put the SQL stuff into the SQL section in the PHPmyadmin tab, but how do I add data to it lol?
import on tab in PhpMyAdmin.
Mythic Fr0st
Forum Contributor
Posts: 137
Joined: Sat Dec 02, 2006 3:23 am
Contact:

hmm

Post by Mythic Fr0st »

Errrm, meaning what?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How new are you to PHP? What I mean by that is have you ever coded any INSERT/UPDATE/DELETE queries before?
Post Reply