PDA

View Full Version : Question Check on duplicate usernames or email address?


Paws
05-30-2007, 09:01 AM
I have created a server behaviour in Dreamweaver to check if an email exists when someone registers at the site but I need to check the username as well.
Any ideas on how to modify this code?

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="userexists.php";
$loginUsername = $_POST['email'];
$LoginRS__query = sprintf("SELECT Email FROM tblogin WHERE Email=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_cnmobile, $cnmobile);
$LoginRS=mysql_query($LoginRS__query, $cnmobile) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);

//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}

davidj
05-30-2007, 10:12 AM
hi mate

im sorry but i dont assist anymore with dreamweaver written code

Paws
05-30-2007, 10:28 AM
That's ok.
It's pretty obvious that you don't have a solution for this one.
I have watched those tuts but dreamweaver offers a much quicker way of completing the code whether it be breakable or not.

Thanks will have to see if someone else has an idea of what to change without breaking it I guess.

davidj
05-30-2007, 10:34 AM
It's pretty obvious that you don't have a solution for this one.

i could do it in 5 seconds flat but it benefits no one


I have watched those tuts but dreamweaver offers a much quicker way of completing the code whether it be breakable or not.


how long have you been stuck with this problem? Add this time onto your "quicker way" then you relise its not that quick. And development speed is a lesser requirement when building robust, scalable applications.


Thanks will have to see if someone else has an idea of what to change without breaking it I guess.

ok

Paws
05-30-2007, 10:44 AM
how long have you been stuck with this problem?I only started this site this morning at bout 6AM and it was complete at 11:38AM due to some extras that I was playing with.8)
These are only questions to help secure the site and it's not a train smash as on all my other sites this wasn't ever needed.
I just wanted to add it to this one.
i could do it in 5 seconds flat but it benefits no oneIt would benefit a lot of coders, as always if you know it show it.8)

davidj I know you prefer to hand code.:)

davidj
05-30-2007, 11:41 AM
It would benefit a lot of coders

no it wouldnt coz coders would know how to do it! Well would know after i guided them a bit

your not a coder when you use wizards to write the stuff. And saying its preferable to handcoding because its quicker is rubbish. You will soon find yourself asking more and more questions and expecting "coders" to write it for you.

i will offer some guidance though...

this is the bit your interested in as this checks the email so just add a $_POST var to catch the user name then query that also in your sql

Its a simple case of adding an AND username in your sql

$loginUsername = $_POST['email'];

$LoginRS__query = sprintf("SELECT Email FROM tblogin WHERE Email=%s", GetSQLValueString($loginUsername, "text"));

Paws
05-30-2007, 11:53 AM
Thank you
I will try it after I finish this other question I asked myself.
Cheers

Paws
06-01-2007, 02:44 PM
This solved it, thanks anyway.


$username = $_POST['username'];
$Password = $_POST['Password'];
$Telephone = $_POST['Telephone'];
$Cellphone = $_POST['Cellphone'];
$status = "OK";
$msg1="";
$msg2="";
$msg3="";
$msg4="";
$msg5="";
if ( strlen($Password) < 6 ){
$msg1='<font face="Verdana" size="2" color="red">6 or more!</font>';
$status= "NOTOK";}
if ( strlen($username) < 6 ){
$msg2='<font face="Verdana" size="2" color="red">6 or more!</font>';
$status= "NOTOK";}
if ( strlen($Telephone) < 10 ){
$msg4='<font face="Verdana" size="2" color="red">Failed!</font>';
$status= "NOTOK";}
if ( strlen($Cellphone) < 10 ){
$msg5='<font face="Verdana" size="2" color="red">Failed!</font';
$status= "NOTOK";}
$quser = "SELECT username FROM tblogin WHERE username = '".$username."'";
$result = mysql_query($quser);
if(mysql_affected_rows()==1){
$msg3='<font face="Verdana" size="2" color="red">Already exists!</font>';
$status= "NOTOK";}
if($status<>"OK"){
} else {


Cheers

davidj
06-01-2007, 02:50 PM
nice one

oh... you dont have to declare your vars in php

You could omit these...

$msg1="";
$msg2="";
$msg3="";
$msg4="";
$msg5="";


this bit is the same for every instance of your messages

<font face="Verdana" size="2" color="red">


you could hard code that into the page coz your repeating string data which is not nessessary so all you would be assigning to the $msg would be the different messages. Its more economical.

Paws
06-01-2007, 03:00 PM
Thank you.

It took me about 15mins to fix this together after "re"viewing a script I got a year ago.

Can you believe that not even Macromedia/Adobe techs know how to solve this without re-writing the entire duplicate username section...:confused: (sad man)

Cheers
Thanks again.