Jump to content

[SOLVED] Preventing identical email and username registrations?


christofurr

Recommended Posts

I give up. I'm posting one last suggestion, take it or leave it.

 

<?php

 if ($result = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '{$_POST['nick']}' || Email_Address = '{$_POST['email']}'")) {
   if (!mysql_num_rows($result)) {
     /*Execute database input*/
   }
 }

?>

 

And... one last time. Integers DO NOT get surrounded in quotes. eg;

 

<?php

  $a = 2;
  
  // not
  $a = "2";

?>

Link to comment
Share on other sites

No, I'm watching all suggestions. I'd just like to understand why mine doesn't work. How can I learn from my mistakes if I just toss out my scripts and copy somebody elses?

 

Now, I'd like ReDucTor to explain his code, and somebody to explain why the query in thorpe's code requires '{}' around the $_POST variable.  :-X

Link to comment
Share on other sites

Well, a few things. For starters, you never check to see if your queries where successfull before trying to use the results. I can tell you now, that your queries both should fail because you fail to wrap your values (eg; $_POST['email') in quotes. I said this quite a few replies ago. (Ignored)

 

I also told you that the cortrect syntax for embeding arrays into double quoted string is to surround them in {} curly braces. (Ignored)

Link to comment
Share on other sites

How's this?

 

<?php
$takenick = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '$nicktrim'");
$takemail = mysql_query("SELECT Email_Address FROM Froobs WHERE Email_Address = '{$_POST['email']}'");

if (mysql_num_rows($takenick) >= 1)
{$error = "A1";}

if (mysql_num_rows($takemail) >= 1)
{$error = "A2";}

if ($error != "A1" && $error != "A2")
{
/*Execute database input*/
}
?>

Link to comment
Share on other sites

Tested and working.

 

One last issue before I hit the Topic Solved button.

 

In my form, I specified that the input values be the input values of the previous submission attempt using the $_POST variable. This works fine for all but some input fields in which the previous input is displayed with a backslash in the middle of it. This happens only in the case where the input includes an apostrophe or a quotation mark.

 

How do I prevent the addition of a backslash?

 

<?php

$recqtrim = trim($_POST["recq"]);

echo "
<input type=\"text\" name=\"recq\" value=\"" . $recqtrim . "\" size=\"35\" maxlength=\"75\" />
";

?>

 

 

Link to comment
Share on other sites

Ok... at minimum you need this to do it using your approuch. Comments explain why.

 

<?php

// ps, ive taken the liberty of formatting your code more traditionaly.
// if you ever want to program larger projects with others, the way you
// format your code will NOT be accepted.

$takenick = mysql_query("SELECT Nickname FROM Froobs WHERE Nickname = '$nicktrim'") or die(mysql_error()); // you want to trap errors here, helps for debugging
$takemail = mysql_query("SELECT Email_Address FROM Froobs WHERE Email_Address = '{$_POST['email']}'") or die(mysql_error()) // same again.

// you'll need to initialize $error to something. Otherwise, if you dont find any results you will get an error in your last if statement.
$error = 0;

// no need to check for >=1, just check if true.
if (mysql_num_rows($takenick)) {
 $error = "A1";
}

if (mysql_num_rows($takemail)) {
 $error = "A2";
}

if ($error != "A1" || $error != "A2") {// you want to check if $error equals A1 or A2, not if it equals both because it can't.
 /*Execute database input*/
}

?>

Link to comment
Share on other sites

Great. One thing, though. I'm checking to see if $error is not equal to A1 or A2. If I check if either isn't true, somebody may be able to register a duplicate nickname with a new email address or a duplicate email address with a new nickname.

 

Sorry... my bad.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.