Jump to content

How to fix submit form to check for username and password in PHP?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
annaright

annaright

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,
can anyone help me with the codes below;


<?php
if(isset($_POST['Submit'])){


//Check For Username
if(strlen($_POST['username'])>0){
$u = TRUE;
}else{
$u = FALSE;
$message .= '<p> You forgot to enter your username!</p>';

//$u =$_POST['username'];
}
//Check For Password
if(strlen($_POST['password1'])>0)
{
//$p = TRUE;
//$message .= '<p> You forgot to enter your password!</p>';
if($_POST['password1'] == $_POST['password2'])
{
$p = TRUE;

}else{
$p = FALSE;
$message .= '<p> Your Password did not match the confirmed password!</p>';
}
}else{
$p = FALSE;
$message .= '<p> Your Forget To Enter Password !</p>';
}

if($u && $p){

$query = "INSERT INTO usersystem (username,password) VALUES ('$u',PASSWORD('$p'))";
$result = mysql_query($query);
if($result){
echo '<p><b> You have been registered!</b></p>';
include ('template/footer,inc');
exit();
}else{
$message = '<p> You could not be registered due to a system error</p><p>'.mysql_error().'</p>';    
}
mysql_close();

}else{

$message .= '<p> Please try again.</p>';    
}
if(isset($message)){
echo '<font color="#FF0000">', $message, '</font>';
}
}

?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<fieldset><legend>Enter Your Information in the form below:</legend>

<p><b> Username:</b> <input type="text" name="username" size="10" maxlength="20" value="<?php if (isset($_POST['username'])) 
echo $_POST['username'];?>"/></p>
<p><b> Password:</b> <input type="password" name="password1" size="20" maxlength="20"/></p>
<p><b> Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20"/></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Register" /></div>
</form>

I tried many time to post the data but nothing happen

Edited by Orjan, 24 October 2011 - 01:36 PM.
Add php tags to your code pieces!


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
Your variables $u and $p contains TRUE or FALSE, not the username or the password, they don't contain a saveable value. Also, please read what the MySQL manual have to say about the PASSWORD() function:

"MySQL Manual" said:

The PASSWORD() function is used by the authentication system in MySQL Server; you should not use it in your own applications. For that purpose, consider MD5() or SHA1() instead.

__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users