PDA

View Full Version : Check new username function


Kamran
08-01-2007, 09:08 PM
Hi there

I was wondering if it's possible to modify the user exists code so that instead of being redirected to another page if the user already exists, the user will be notified of the error on the same page?
I can get an error message to appear without the redirect, but the already existing user login ID is still inserted into the database.

Here is the original DMX code for the user exists function, I would be grateful if anyone can suggest what I should change in order to get the effect I want. Thanks

<%
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "") Then
MM_dupKeyRedirect="user_exists.asp"
MM_rsKeyConnection=MM_AFLconnect_STRING
MM_dupKeyUsernameValue = CStr(Request.Form("email"))
MM_dupKeySQL="SELECT Email FROM Consumers WHERE Email='" & MM_dupKeyUsernameValue & "'"
MM_adodbRecordset="ADODB.Recordset"
set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
MM_rsKey.ActiveConnection=MM_rsKeyConnection
MM_rsKey.Source=MM_dupKeySQL
MM_rsKey.CursorType=0
MM_rsKey.CursorLocation=2
MM_rsKey.LockType=3
MM_rsKey.Open
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%>

Paws
08-01-2007, 09:29 PM
Not that simple as I am not sure exactly which part you would change to PHP_SELF

Remember to place the "$msg3" after the text boxes like:
<?php echo $msg3;?>

You could change this
MM_dupKeyRedirect="user_exists.asp"
to
MM_dupKeyRedirect=$_SERVER['PHP_SELF']; but not sure if that will work as have not tested it yet anyway.


<?php
if(isset($_POST['subbutton'])){

$username = $_POST['username'];
$Password = $_POST['Password'];

$status = "OK";
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";}
$quser = "SELECT username FROM table 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 {
//the rest of your dreamweaver code.
?>
Hope that helps you.

Kamran
08-01-2007, 10:01 PM
Hi there

I am using ASP, so your solution doesn't make a lot of sense to me! Thanks for responding though. :)

Paws
08-01-2007, 10:21 PM
Sorry try this instead.

<?php
Dim username, password, msg1, msg2, msg3, status
username = Request.Form("username")
password = Request.Form("password")

status = "OK"
if Len(password) < 6 then
msg1='<font face="Verdana" size="2" color="red">6 or more!</font>';
status= "NOTOK";
end if
if Len(username) < 6 then
msg2='<font face="Verdana" size="2" color="red">6 or more!</font>';
status= "NOTOK";
end if
'if some query
'NOT SURE ABOUT THE QUERY HERE FOR CHECKING THE USERNAME THOUGH!
msg3='<font face="Verdana" size="2" color="red">Already exists!</font>';
status= "NOTOK"
if status != "OK"
else
//the rest of your dreamweaver code.
?>

m1a2x3x7
08-04-2007, 11:22 PM
i think the whole point is to have it work for asp not for him to switch to php

sorry man im not help when it comes to asp