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!
I'm working on a site for a my friends and I to post our homework. So far I have a lot of it done but I need to make sure a username isn't used twice. How would you go about doing this?
This is what I have so far for the user registration function.
function register($user, $pass, $email, $email_redo) {
if($email != $email_redo) {
header("location: {$page['register']}?msg=emailmatch");
}
$sql = mysql_query("Insert into users (user, pass, email) VALUES('$user', '$pass', '$email')") or die(mysql_error());
$msg = "$user, thank you for siging up on {$site['url']} . \n Your login information is \n user: $user \n password: $pass";
$msg2 = wordwrap($msg, 70);
mail($email, "Your Login information for the hw site", $msg2);
}
select off of the database first to make sure the name isn't in there. If the row count is > 0, display an error message. Also, make your field unique in mysql so it won't allow the insert to happen if it gets past that point somehow.
Burrito wrote:select off of the database first to make sure the name isn't in there. If the row count is > 0, display an error message. Also, make your field unique in mysql so it won't allow the insert to happen if it gets past that point somehow.
function register($user, $pass, $email, $email_redo) {
if($email != $email_redo) {
header("location: {$page['register']}?msg=emailmatch");
}
$check = mysql_query("select * from users") or die(mysql_error());
$rows = mysql_num_rows($check);
if($rows > 0) {
die("There is someone with the same account name already");
}
$sql = mysql_query("Insert into users (user, pass, email) VALUES('$user', '$pass', '$email')") or die(mysql_error());
$msg = "$user, thank you for siging up on {$site['url']} . \n Your login information is \n user: $user \n password: $pass";
$msg2 = wordwrap($msg, 70);
mail($email, "Your Login information for the hw site", $msg2);
}