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";

?>

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

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)

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*/
}
?>

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\" />
";

?>

 

 

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*/
}

?>

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.