Jump to content

simple question on regester validator


lukelee

Recommended Posts

Here is my code, there are 3 inputs, username, password and repeat_password, both of them cant be null, and password must be same as repeat_password. otherwise, shows error message. but my code doesnt work, i think there must be something wrong in if condition.

 

$username = $_POST[username];
$password = $_POST[password];
$repeat_password = $_POST[repeat_password];
if(($username && $password && $repeat_password!= 0) && ($password==$repeat_password || $password))
{
    
$query = mysql_query("UPDATE admin SET username='$username',passwd='$password' where id='1'");

echo "detail has been changed, you will be redirecting to previous page in 3 seconds";
}
else {
echo "ERROR..... please check the contents you have entered.";

Link to comment
https://forums.phpfreaks.com/topic/135459-simple-question-on-regester-validator/
Share on other sites

Try this instead:

 

<?php

$username = $_POST[username];
$password = $_POST[password];
$repeat_password = $_POST[repeat_password];
if(($username && $password && $repeat_password != null) && ($password == $repeat_password || $password))
{
   $query = mysql_query("UPDATE admin SET username='$username',passwd='$password' where id='1'");
   echo "detail has been changed, you will be redirecting to previous page in 3 seconds";
}
else
{
   echo "ERROR..... please check the contents you have entered.";
}

?>

 

You may also want to add additional checks for the validity of the inputs. Minimum length, proper character types, etc. Right now they'll take anything, like a single space.

Archived

This topic is now archived and is closed to further replies.

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