Jump to content


Form Validation

  • Please log in to reply
No replies to this topic

#1 beav33

  • Members
  • PipPip
  • Member
  • 25 posts

Posted 25 July 2006 - 11:45 PM

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
if (isset($_POST[$MM_flag])) {
  $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
    $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");

$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

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,

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users