Jump to content

Please help with field validation


lingo5

Recommended Posts

Hi,

I have this form to create a new user:

 

<form action="<?php htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" on>
  <table width="850" border="0" align="center" cellpadding="8" cellspacing="0">
    <tr>
      <td><table width="100%" border="0" cellspacing="0" cellpadding="10">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="6">
            <tr>
              <td><span class="CP_blueTXT">Nombre de la persona autorizada</span></td>
            </tr>
            <tr>
              <td>
                <input name="usuario_nombre" type="text" class="CP_loginFormFields" id="usuario_nombre" size="32" /></td>
            </tr>
          </table></td>
        </tr>
      </table>
        <table width="100%" border="0" cellpadding="10" cellspacing="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="6">
              <tr>
                <td><span class="CP_blueTXT">Nombre de usuario</span></td>
              </tr>
              <tr>
                <td>
                  <input name="usuario" type="text" class="CP_loginFormFields" id="usuario" size="32" /> <span class="CP_SiNoText"><?php echo isset($errorMsg) ? $errorMsg : '';?></span></td>
              </tr>
            </table></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="10">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="6">
              <tr>
                <td><span class="CP_blueTXT">Contraseña</span></td>
              </tr>
              <tr>
                <td>
                  <input name="password" type="text" class="CP_loginFormFields" id="password" size="32" /></td>
              </tr>
            </table></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="6">
              <tr>
                <td width="2%"> </td>
                <td width="98%"><input name="upload" type="submit" class="box" id="upload" value=" crear usuario" /></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
    </tr>
  </table>
</form>

 

...and I use this query to cretae a new user record:

 

$colname_checkdup_RS = "-1";  // this checks that if the user entered is already in database
if (isset($_POST['usuario'])) {
  $colname_checkdup_RS = $_POST['usuario'];
}
mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_checkdup_RS = sprintf("SELECT * FROM t_usuario WHERE usuario = %s", GetSQLValueString($colname_checkdup_RS, "text"));
$checkdup_RS = mysql_query($query_checkdup_RS, $MySQLconnect) or die(mysql_error());
$row_checkdup_RS = mysql_fetch_assoc($checkdup_RS);
$totalRows_checkdup_RS = mysql_num_rows($checkdup_RS);

if($totalRows_checkdup_RS==1)
{
$errorMsg =  "el usuario introducido ya existe en la base de datos"; // duplicate entry found message
}

else{

$query = "INSERT INTO eu45antinew.t_usuario (usuario_nombre,usuario,password) ".
"VALUES ('$usuario_nombre','$usuario','$password')";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); 


//echo "<br>Files uploaded<br>";

header("Location: PC_users_display.php"); 
}
}
?>

 

The query includes a function to check if the value entered in "user" already exists. This works fine, but I want the field "user" to be an email address...so I would like to validate that field...how can I do that?

Thanks

 

Link to comment
Share on other sites

What you can do is set the email field in your table to be unique. Doing that the query will return an error if the email already exists. By doing it like this, you also don't need to select anything first to validate. You just run the INSERT query, and check what the response from the database is

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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