Changing contents of a variable

Asked

Viewed 38 times

-2

Guys, is there any way I can alter the field exact of a php variable. What I have is this: A file called mudarpassword.php

<?php
if (isset($_POST['clicado'])) {
    $file = fopen('dados_acesso.php','r+');
    $email = $_POST['end_email'];
    $fmail = $email.PHP_EOL;
    fwrite($file,$fmail);
    fclose($file); 
    print_r(error_get_last());

    //Mudar URL para senha alterada com sucesso! header("Location: http://www.google.com") ; 
}

?>
<form action='mudarsenha.php' method='post'>
    <input type='password' name ='end_email' size= '30'/>
    <br />
    <br />
    <input type='submit' name='clicado' value='Alterar'/>
    <br />
</form>

that has a form that I write in another file called dados_access.php and in this is a simple file containing simply this:

<?php
$user = "tavares";
$senha = "123";
echo "Sua senha atual é: $senha"
?>

everything "works" but with each insertion in the form the data is inserted in the first line of the file dados_access.php and what I need is to make a change and not add content. in that case I want to enter the data by form. the content of the variable is updated $password

Could someone give me a light? I’m new yet. I’ll be grateful.

  • 1

    pq does not write to a database? anyway r+ increments the file you have to rewrite it from 0 with the content q wants to save. Uses w

  • this will help you: https://www.w3schools.com/php/php_file_create.asp

  • Thank you. I should actually use the bank, but as it is a system that runs on localhost only. I didn’t want to "invest" so long no. But thanks for the tip too, I’ll give a study.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.