Hi, I'm using dreamweaver CS3 they provide behavior for checkout username, but what I do not like if user name exit that will redirect to other page inform them that user name is exit., I'm trying to do is to change code to show message inside of same page using javascripts instead of going to other page. But I couldn't figure out what to change code.

Please see part of this code in php, as you can see in code in bold, how is possible that i can change by not rediect to other page but stay same page and point the javascripts function called username(), to say user name is exit!

does any one can help me please. thanks.

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  [B]$MM_dupKeyRedirect="UserExit.php";[/B]
  $loginUsername = $_POST['four'];
  $LoginRS__query = sprintf("SELECT User_Name FROM signup WHERE User_Name=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_RegData, $RegData);
  $LoginRS=mysql_query($LoginRS__query, $RegData) 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;
  }
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO signup (First_Name, Last_Name, Email, User_Name, Password, Password2) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['one'], "text"),
                       GetSQLValueString($_POST['two'], "text"),
                       GetSQLValueString($_POST['three'], "text"),
                       GetSQLValueString($_POST['four'], "text"),
                       GetSQLValueString($_POST['five'], "text"),
                       GetSQLValueString($_POST['six'], "text"));

  mysql_select_db($database_RegData, $RegData);
  $Result1 = mysql_query($insertSQL, $RegData) or die(mysql_error());

  $insertGoTo = "../MemberIndex.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

    instead of

    header ("Location: $MM_dupKeyRedirect");

    just echo an error message.

      thanks for your help but i have tried that is not working right i do don't know if i'm wriing right code
      here is

      header ("<script type="text/javascript">checkusername();</script>");

      but is not pointing to the javascripts function called checkusername(), any idea why!

        because its not valid php, your already using php to check user name why do you need the js at all?

          the reason I'm writing in javascripts becuase in registration form i have wrote each text field validation, for sample that if first password are not same second password then will show slide down error from the bottom of text field that using from ajax code. so what i wrote code is to call javascripts function if there is any valiadation.

          And now I'm trying to do samething for check user name, if user name already exit then it will called javascripts function to show slide down image that said "user name is already exit" instead of going to other page to show errors.

          i know that code in javascripts i wrote inside of php, but is there is way that can be done if user name exit then call the javascripts function!

          please help.

            header ("<script type="text/javascript">checkusername();</script>");
            change to
            echo '<script type="text/javascript">checkusername();</script>';

              Write a Reply...