Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help Verify Username

    okays. I need a little help lol.

    What i need to achieve is for the page to check if the value put into the textfield "username" isnt a repeated value before it posts or submits the page.

    any help would be appreciated.


    heres my page code:


    PHP Code:
    <?php require_once('Connections/data.php'); ?>
    <?php 
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }
    $error '';
    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {  
    if (
    $_POST['password'] != $_POST['verify']) 
    {
    $error '<b><font color="red">The Passwords Did Not Match!</font></b>';} 
      if (!empty(
    $_POST['username']) && !empty($_POST['password']) &&  
        !empty(
    $_POST['ident']) && !empty($_POST['firstname']) &&  
        !empty(
    $_POST['lastname']) && !empty($_POST['thoughts']) &&  
        !empty(
    $_POST['is_reg']) && $_POST['password'] == $_POST['verify']) 
        
      { 
      
    $insertSQL sprintf("INSERT INTO guest_blog_user_id (username, password, ident, firstname, lastname, thoughts, Is_Reg) VALUES (%s, %s, %s, %s, %s, %s, %s)"
                           
    GetSQLValueString($_POST['username'], "text"), 
                           
    GetSQLValueString($_POST['password'], "text"), 
                           
    GetSQLValueString($_POST['ident'], "text"), 
                           
    GetSQLValueString($_POST['firstname'], "text"), 
                           
    GetSQLValueString($_POST['lastname'], "text"), 
                           
    GetSQLValueString($_POST['thoughts'], "text"), 
                           
    GetSQLValueString($_POST['is_reg'], "text")); 

      
    mysql_select_db($database_data$data); 
      
    $Result1 mysql_query($insertSQL$data) or die(mysql_error()); 

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

    mysql_select_db($database_data$data);
    $query_reg_user "SELECT * FROM guest_blog_user_id";
    $reg_user mysql_query($query_reg_user$data) or die(mysql_error());
    $row_reg_user mysql_fetch_assoc($reg_user);
    $totalRows_reg_user mysql_num_rows($reg_user);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <LINK REL="SHORTCUT ICON" HREF="images/favicon.ico">
    <title>Register</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    body {
        background-color: #191919;
    }
    #apDiv4 {
        position:absolute;
        width:704px;
        height:565px;
        z-index:1;
        left: 37px;
        top: 3px;
    }
    }
    a:link {
        color: #FFFFFF;
    }
    a:visited {
        color: #FFFFFF;
    }
    a:hover {
        color: #CCCCCC;
    }
    a:active {
        color: #FFFFFF;
    }
    .style1 {font-size: 12px}
    .style3 {font-size: 18px}
    .style9 {font-size: 14}
    .style11 {font-size: 12px; font-family: "Times New Roman", Times, serif; }
    .style12 {font-family: "Times New Roman", Times, serif}
    body,td,th {
        color: #FFFFFF;
    }
    .style14 {color: #000000}
    .style15 {font-size: 14px; font-style: italic; font-weight: bold; color: #FFFFFF; }
    </style>
    <script type="text/javascript">
    <!--
    function validateForm() {
    with (document.form1) {
    var alertMsg = "The following\nhave been left empty:\n";
    if (title.value == "") alertMsg += "\ntitle";
    if (post.value == "") alertMsg += "\npost";
    if (postedby.value == "") alertMsg += "\npostedby";
    if (alertMsg != "The following\nhave been left empty:\n") {
    alert(alertMsg);
    return false;
    } else {
    return true;
    } } }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_validateForm() { //v4.0
      var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
      for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
        if (val) { nm=val.name; if ((val=val.value)!="") {
          if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
          } else if (test!='R') { num = parseFloat(val);
            if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
            if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
              min=test.substring(8,p); max=test.substring(p+1);
              if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
        } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
      } if (errors) alert('The following error(s) occurred:\n'+errors);
      document.MM_returnValue = (errors == '');
    }
    //-->
    </script>

    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <div id="apDiv1" style="position: absolute; left: 71px; top: 19px; width: 820px; height: 42px; z-index: 1; background-image: url(images/regist_02.png); layer-background-image: url(images/regist_02.png); border: 1px none #000000;"></div>
    <div id="apDiv2" style="position: absolute; left: 71px; top: 61px; width: 820px; height: 568px; z-index: 2; background-image: url(images/regist_03.png); layer-background-image: url(images/regist_03.png); border: 1px none #000000;">
      <div id="apDiv4">
        <p>&nbsp;</p>
        <table width="552" height="286" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="179" align="center" valign="top"><p class="style1">&nbsp;</p>
            <p class="style11">Registeration needs to be processed before you are able to login with credentials. Please allow 48 hours for this to happen. Multiple requests will be disregarded, and the IP address of the requester will be blocked for a week.</p>
          <p class="style11">&nbsp;</p>
          <p class="style11">Please Provide Your Name, and thoughts about the website.</p>
          <p class="style11">Your information will remain safe.</p>
          <p class="style11">If your form does not submit to a confirmation page, you have entered <strong>2 different passwords</strong>. Please make sure they are the same. </p>
          <p class="style11">&nbsp;</p>
          <p class="style11">&nbsp;</p>
          <p class="style11"><a href="login.php"><strong>Go Back</strong></a></p></td>
        <td width="367" align="center" valign="top"><span class="style12"><strong>&nbsp;<span class="style3">Registration Form </span></strong>
            </span><br />
            <?php
    if (!empty($error))
    {
        echo 
    '<div id="errorMsg">' $error '</div>';
    }
    ?>
          <form action="<?php echo $editFormAction?>" method="post" name="form1" class="style12" onsubmit="MM_validateForm('firstname','','R','lastname','','R','username','','R','thoughts','','R','password','','R');return document.MM_returnValue">
            <table align="center">
              <tr valign="baseline">
                <td height="38" align="center" valign="middle" nowrap><div align="center" class="style15">First Name:</div></td>
                <td valign="middle"><div align="center" class="style9">
                      <input name="firstname" type="text" class="style1" value="" size="26" />
                </div></td>
              </tr>
              <tr valign="baseline">
                <td height="38" align="center" valign="middle" nowrap><div align="center" class="style15">Last Name:</div></td>
                <td valign="middle"><div align="center" class="style9">
                      <input name="lastname" type="text" class="style1" value="" size="26" />
                </div></td>
              </tr>
              <tr valign="baseline">
                <td height="42" align="center" valign="middle" nowrap><div align="center" class="style15">Username:</div></td>
                <td valign="middle"><div align="center" class="style9">
                      <input name="username" type="text" class="style1" value="" size="32" maxlength="12" />
                </div></td>
              </tr>
              <tr valign="baseline">
                <td height="48" align="center" valign="middle" nowrap><div align="center" class="style15">Password:</div></td>
                <td valign="middle"><div align="center" class="style9">
                      <input name="password" type="password" maxlength="12" class="style1" value="" size="32" />
                </div></td>
              </tr>
              <tr align="center" valign="middle">
                <td height="40" nowrap><span class="style15">Verify:</span></td>
                <td><label>
                  <input name="verify" type="password" class="style1" id="verify" size="32" maxlength="12" />
                </label></td>
              </tr>
              <tr valign="baseline">
                <td height="102" align="center" valign="middle" nowrap><div align="center" class="style15">Thoughts:</div></td>
                <td valign="middle"><div align="center" class="style9">
                      <textarea name="thoughts" cols="32" rows="5" class="style1"></textarea>
                </div></td>
              </tr>
              <tr valign="baseline">
                <td nowrap align="right"><span class="style14"></span></td>
                <td valign="middle"><div align="center" class="style9">
                      <input name="submit" type="submit" value="Submit Registration" />
                </div></td>
              </tr>
            </table>
            <input type="hidden" name="ident" value="<?php echo $_SERVER["REMOTE_ADDR"]; ?>" />
            <input type="hidden" name="is_reg" value="no" />
            <input type="hidden" name="MM_insert" value="form1" />
          </form>    </td>
      </tr>
    </table>
      </div>
    </div>
    <div id="apDiv3" style="position: absolute; left: 71px; top: 629px; width: 820px; height: 45px; z-index: 3; background-image: url(images/regist_04.png); layer-background-image: url(images/regist_04.png); border: 1px none #000000;"></div>
    <div id="apDiv5" style="position: absolute; left: 0px; top: 0px; width: 1px; height: 710px; z-index: 5"></div>

    </body>
    </html>
    <?php
    mysql_free_result
    ($reg_user);
    ?>



    Also here is data.php:


    PHP Code:
    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_data "localhost";
    $database_data "web1_db1";
    $username_data "web1_u1";
    $password_data "**********";
    $data mysql_pconnect($hostname_data$username_data$password_data) or trigger_error(mysql_error(),E_USER_ERROR); 
    ?>
    Last edited by 40esp; 07-15-2007 at 10:45 PM.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    I'm not exactly sure what that first part of source code is you posted, it looks like a pre-canned function but I don't see where it helps you with what you are trying to do.

    I assume you want to make sure there are no dupe usernames in your database? Then you should just take the username input and try to do a find in your database. If the find is successful you have a dupe, if not, then you can continue and create the account.

    You'll want to do something like this:

    $php_SQL = "SELECT * FROM Users WHERE username = '".$php_username."';
    $php_resultID = mysql_query($php_SQL, $php_linkID);
    $php_count = mysql_num_rows($php_resultID);
    if ($php_count == 0)
    {
    // no dupe found
    }
    else
    {
    // dupe username found
    }
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rfresh View Post
    I'm not exactly sure what that first part of source code is you posted, it looks like a pre-canned function but I don't see where it helps you with what you are trying to do.

    I assume you want to make sure there are no dupe usernames in your database? Then you should just take the username input and try to do a find in your database. If the find is successful you have a dupe, if not, then you can continue and create the account.

    You'll want to do something like this:

    $php_SQL = "SELECT * FROM Users WHERE username = '".$php_username."';
    $php_resultID = mysql_query($php_SQL, $php_linkID);
    $php_count = mysql_num_rows($php_resultID);
    if ($php_count == 0)
    {
    // no dupe found
    }
    else
    {
    // dupe username found
    }

    how would i code that with my form and textbox?



    the top code is the current page code i want to apply this to.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •