Check if the record already exists, if it does not change the value (MYSQL)

0

PHP FUNCTIONS

<?
if($_REQUEST['salva_ed']){
    $sqlu="update registration set username='$username', firstname='$fname',  lastname='$lname', sex='$gender',
            birth_date='$bdate', addressline1='$address1',addressline2='$address2', complemento='$address3', numero='$address4', city='$city',  state='$state',
            country='$country', postcode='$zipcode', phone='$phone', mobile_no='$mobileno', full_mobileno='$fullmobile',
            email='$email', password=MD5('$pass'), cpf='$cpf',rg='$rg'  where id='$id'";
    $resultu=mysql_query($sqlu);
    header("location:message.php?msg=3"); exit;
}


if($_REQUEST['salva_nv']){
    $verifcode = md5($username);
    $agora=Date("Y-m-d H:i:s");
    $sqlu="insert into registration (username,firstname,lastname,sex,birth_date,addressline1,addressline2,city,state,
            country,postcode,phone,mobile_no,full_mobileno,email,password,cpf,rg,register_date,verify_code,
            final_bids,account_status,member_status,user_delete_flag,sponser,sms_flag,admin_user_flag) values
            ('$username','$fname','$lname','$gender','$bdate','$address1','$address2','$address3','$address4','$city','$state',
            '$country','$zipcode','$phone','$mobileno','$fullmobile','$email',MD5('$pass'),'$cpf','$rg','$agora','$verifcode',
            0,0,'0','',0,'0','0')";
            //echo $sqlu; exit;
    $resultu=mysql_query($sqlu);
    header("location:message.php?msg=2"); exit;
}
?>

HTML

<tr>
 <td class="normal" align="right"><font class="a">*</font>&nbsp;Senha de acesso:&nbsp;</td>
 <td><input style="width:60%" type="password" name="pass_word" value="<?=$pass?>"/></td>
</tr>
<tr>
 <td class="normal" align="right"><font class="a">*</font>&nbsp;Confirma&ccedil;&atilde;o de senha:&nbsp;</td>
 <td><input style="width:60%" type="password" name="cpassword" value="<?=$pass?>"/></td>
</tr>
    <input type="submit" value="Atualizar cadastro" name="Editar" class="bttn" /></td>

Personally, I have a problem here and I could not find a solution.

This is an admin panel, I implemented it to save MD5 passwords in DB.

There are two functions, one to execute when you are editing a current client and another to create a new client (salva_nv) ...

The problem is in the function of editing the client (salva_ed), in the password fields.

When I edit it it again changes the client password generating another MD5.

How do I check if the registry is the same in the column, and not replace the current password?

When loading the page it automatically fills in the fields with the current password, however it shows in MD5, so if I save it it will change in the DB generating a new MD5 key.

I saw on the internet that it is possible to use "constraint" to accomplish this task, but I could not implement it.

Does anyone have any tips?

    
asked by anonymous 06.10.2016 / 21:48

2 answers

0

I do not know how to do with constraint but I would do it like this:

if($_REQUEST['salva_ed'] && $pass && $pass != ''){
$sqlu="update registration set username='$username', firstname='$fname',  lastname='$lname', sex='$gender',
        birth_date='$bdate', addressline1='$address1',addressline2='$address2', complemento='$address3', numero='$address4', city='$city',  state='$state',
        country='$country', postcode='$zipcode', phone='$phone', mobile_no='$mobileno', full_mobileno='$fullmobile',
        email='$email', password=MD5('$pass'), cpf='$cpf',rg='$rg' where id='$id' AND password != '$pass'";
$resultu=mysql_query($sqlu);
header("location:message.php?msg=3"); exit;
}

That way in the where it checks if the password is different from what is being suggested (without converting it to md5)

    
06.10.2016 / 22:19
1

You can leave a warning on the system speaking to leave blank if you do not want to change the password and do so:

    if($_REQUEST['salva_ed']){
if(!empty($pass){$sqlu="update registration set username='$username', firstname='$fname',  lastname='$lname', sex='$gender',
        birth_date='$bdate', addressline1='$address1',addressline2='$address2', complemento='$address3', numero='$address4', city='$city',  state='$state',
        country='$country', postcode='$zipcode', phone='$phone', mobile_no='$mobileno', full_mobileno='$fullmobile',
        email='$email', password=MD5('$pass'), cpf='$cpf',rg='$rg'  where id='$id'";}else{$sqlu="update registration set username='$username', firstname='$fname',  lastname='$lname', sex='$gender',
        birth_date='$bdate', addressline1='$address1',addressline2='$address2', complemento='$address3', numero='$address4', city='$city',  state='$state',
        country='$country', postcode='$zipcode', phone='$phone', mobile_no='$mobileno', full_mobileno='$fullmobile',
        email='$email', cpf='$cpf',rg='$rg'  where id='$id'";}
$resultu=mysql_query($sqlu);
header("location:message.php?msg=3"); exit;}
    
07.10.2016 / 16:43