Jump to content

Recommended Posts

I'm trying to get javascript to validate my password and confirm password but it's not working. It does validate if my fields are not null but won't check to see if the passwords match. Any help would be greatly appreciated.
[code]
<? include ("mysql_connect.php")?>
<html>
<head>
<title>Seven Deadly Sins - Tournament - Register User</title>

<script type="text/javascript">
function validate(uname,pass,pass1,fname,lname,email)
{
    // do various checks, this will save people noticing mistakes on next page
    if (uname.value == '' || pass.value == '' || pass1.value == '' || fname.value == '' || lname.value == '' || email.value == ''){
        if(pass.value == pass1.value){
            alert('Your password did not match the confirmed password.');
            return false;    
            }else{
               return true;  
          }
        
    
        alert('Please fill out all fields.');
        return false;
    }
    else
    {
        return true;
    }
    return false;
}

  
</script>
</head>

<body>






<?php

// Run MySQL query to retrieve clan list

$query=("SELECT clanname FROM clans");
$result=mysql_query($query)or die ('Query could not be processed:
'.mysql_error());


IF (isset($_REQUEST["uname"])){
    $uname = $_REQUEST["uname"];
    $pass = $_REQUEST["pass"];
    $pass1 = $_REQUEST["pass1"];
    $fname = $_REQUEST["fname"];
    $lname = $_REQUEST["lname"];
    $email = $_REQUEST["email"];
    $clanname = $_REQUEST["clanname"];
    $hashedp = md5($p);
    $emaillist=$_REQUEST['emaillist'];


// Start insert query after submit is set.

     $query=("INSERT INTO users (uname, pass, fname, lname, email, clanname,
     emaillist) VALUES
     ('$uname','$hashedp','$fname','$lname','$email','$clanname','$emaillist')");
     $result1=mysql_query($query)or die ('Your query could not be processed:
     '.mysql_error());

       IF ($result1){
       echo "You have been registered!";
       }
  
}
?>

<fieldset><form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"
onsubmit="return validate(uname,pass,pass1,fname,lname,email);">
<legend><strong>User Registration: </strong></legend>
<table><tr><td>
Login Name:</td><td> <input type="text" name="uname" value=""></td></tr><tr><td>
Pass: </td><td><input type="password" name="pass" value=""></td></tr><tr><td>
Confirm Pass: </td><td><input type="password" name="pass1" value=""></td></tr><tr><td>
First Name: </td><td><input type="text" name="fname" value=""></td></tr><tr><td>
Last Name: </td><td><input type="text" name="lname" value=""></td></tr><tr><td>
E-mail: </td><td><input type="text" name="email" value=""></td></tr><tr><td>
*clan: </td><td> <select name="clanname" >

<?php
while($row = mysql_fetch_assoc($result)){
echo '<option value="' . htmlspecialchars($row['clanname']) . '">' .
$row['clanname'] . '</option>';
}
?>

</td></tr><tr><td>
<input type="checkbox" name="emaillist" value="1"></td><td> If you would
like to receive an email informing you of the next tourney check this box.
</td></tr><tr><td></td><td>
* You must have a clan registered to register as a
user.</td></tr><tr><td></table>
<input type="submit" value="submit" >
</form></fieldset>

<?php
        




mysql_close(); ?>

  </body>
  </html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/3733-password-confirmation-check/
Share on other sites

  • 2 weeks later...
The way your function currently reads is:
If any of the fields are empty, check to see if the password and confirm password fields match.

function chkForm(frm)
{
if (frm.uname.value == "")
{
alert("Please enter a user name");
frm.uname.focus();
return false;
}

if (frm.pass.value == "")
{
alert("Please enter a password");
frm.pass.focus();
return false;
}

if (frm.pass1.value == "")
{
alert("Please confirm your password");
frm.pass1.focus();
return false;
}

if (frm.fname.value == "")
{
alert("Please enter your first name");
frm.fname.focus();
return false;
}

if (frm.lname.value == "")
{
alert("Please enter your last name");
frm.lname.focus();
return false;
}

if (frm.email.value == "")
{
alert("Please enter your email");
frm.email.focus();
return false;
}

if (frm.pass.value != frm.pass1.value)
{
alert("Your password and confirmation do not match");
frm.pass.focus();
return false;
}

return true;
}

<form name="myForm" id="myForm" action="somePage" method="post" on submit = "return chkForm(this)">
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.