Jump to content

Form Validation


Recommended Posts

This is some of the code below that dreamweaver places for a registration record set. Now I want to validate some things like making sure the passwords match up and email, so on. I can't figure out how to change my code to identify it. My code is below dreamweavers, please help.

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
  $MM_dupKeyRedirect="takenusername.php";
  $loginUsername = $_POST['username'];
  $LoginRS__query = sprintf("SELECT username FROM register WHERE username=%s", GetSQLValueString($loginUsername, "text"));
  mysql_select_db($database_db_connect, $db_connect);
  $LoginRS=mysql_query($LoginRS__query, $db_connect) 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 register (username, password, email, companyname, firstname, lastname, phone) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['username'], "text"),
                      GetSQLValueString($_POST['password'], "text"),
                      GetSQLValueString($_POST['email'], "text"),
                      GetSQLValueString($_POST['companyname'], "text"),
                      GetSQLValueString($_POST['firstname'], "text"),
                      GetSQLValueString($_POST['lastname'], "text"),
                      GetSQLValueString($_POST['phone'], "text"));

Dreamweaver's way to check username and varibles.
My code
  //create short variable names
  $email=$_POST['email'];
  $username=$_POST['username'];
  $password=$_POST['password'];
  $password2=$_POST['password2'];
  $companyname=$_POST['companyname'];
  $firstname=$_POST['firstname'];
  $lastname=$_POST['lastname'];
  $phone=$_POST['phone'];

Then on down the validation

    // passwords not the same
    if ($password != $password2)
    {
      throw new Exception('The passwords you entered do not match - please go back'
                          .' and try again.');

Just need to change it up a bit to work with dreamweaver's code. BUT HOW?
Thank you,
beav33
   
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.