Help to change SESSION variables

-4

I need to change the values of the SESSION's name, login and password, but I'm not getting it.

I think the problem is in this part of the code,

if(!isset($_SESSION['usuario'])){ // Se a Session não for iniciada
$nome = 'Nome do Usuário'; // Carrega esse conteúdo
$login = 'usuario'; // Carrega esse conteúdo
$senha = '123'; // Carrega esse conteúdo

}else{

if(isset($_SESSION)){ // Se a Session for iniciada

Because when I remove it, I can at least save the changes to SESSION's using WAMPSERVER.

Below is the code I'm using along with the link address so friends can check what's going on, or whatever is not happening;).

Code:

<?php
@session_start(); // Inicia a session.

if(!isset($_SESSION['usuario'])){ // Se a Session não for iniciada
$nome = 'Nome do Usuário'; // Carrega esse conteúdo
$login = 'usuario'; // Carrega esse conteúdo
$senha = '123'; // Carrega esse conteúdo

}else{

if(isset($_SESSION)){ // Se a Session for iniciada
$nome = $_SESSION["nome"];
if($nome) {
$login = $_SESSION["login"];
if($login) {
$senha = $_SESSION["senha"];
if($senha) {
}}}}}
?>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

<label>Nome do Usuário: </label><span><?php echo $nome ?></span><br /><br />
<label>Login do Usuário: </label><span><?php echo $login ?></span><br /><br />
<label>Senha do Usuário: </label><span><?php echo $senha ?></span><br /><br />

<form method="post">    
<label>Nome do Usuário:</label><br />
<input type="text" name="nome" value="<?php echo $nome ?>"><br /><br />
<label>Login do Usuário:</label><br />
<input type="text" name="login" value="<?php echo $login ?>"><br /><br />
<label>Senha do Usuário:</label><br />
<input type="text" name="senha" value="<?php echo $senha ?>"><br /><br />
<input type="submit" value="Atualizar" />
</form>

<?php
$nome = $_POST["nome"];
if($nome) {
$_SESSION["nome"] = $nome ;

$login = $_POST["login"];
if($login) {
$_SESSION["login"] = $login ;

$senha = $_POST["senha"];
if($senha) {
$_SESSION["senha"] = $senha ;

header('Location:index.php');
}}}
?>

Looking forward to good tips, and thank you all for your attention. Hugs.

    
asked by anonymous 25.05.2016 / 01:46

3 answers

2

Well if I were to do that, in case it should be what you want to do I would do so.

 <?php 
@session_start(); // Inicia a session.

         if(!isset($_SESSION['usuario'])){ 
      // Se a Session não existir eu crio...
        $nome = 'Nome do Usuário'; // Carrega esse conteúdo
        $login = 'usuario'; // Carrega esse conteúdo
        $senha = '123'; // Carrega esse conteúdo

    //Armazena os dados na sessão que pode ser bidimensiona(array)
         $_SESSION['usuario']['nome']=$nome;
        $_SESSION['usuario']['login']=$login;
        $_SESSION['usuario']['senha']=$senha;

        }else if(isset($_SESSION['usuario'])){
         // Se existir sessão, eu crio aqui
        $nome = $_SESSION['usuario']["nome"];
        $login = $_SESSION['usuario']["login"];
        $senha = $_SESSION['usuario']["senha"];
    }
        ?>

There at the bottom of the code, in the form submission, it would be recommended that you do so. First change the button by putting the name of it

<input type="submit" value="Atualizar" name="atualizar"/>

Ai in php ...

      <?php 
    //pega o valor do botao
    $botao=$_POST['atualizar'];
    //verifica se o botao foi clicado
    if($botao=="Atualizar"){
       $nome = $_POST["nome"];
       $login = $_POST["login"];
       $senha = $_POST["senha"];
            if(!empty($nome) && !empty($login) && !empty($senha)) {
            $_SESSION['usuario']["nome"] = $nome ;
            $_SESSION['usuario']["login"] = $login ;
            $_SESSION['usuario']["senha"] = $senha ;

            header('Location:index.php');
            }}
        ?>

I think if I understood your problem correctly, that will solve it. Because there in your code you take the name of a session where I do not know where you created, which in the case does not exist, because it would be the session user and not name, password ... In case, I did not understand your situation right, I'll comment on it so I can help you better. I did not move in these IFs there in the end, but to give an improvement ...

Update: I would do this with these IFs, instead of the 3, I would do it all in one go. And if you have never used it, this empty () function, it checks if the variable is empty, which in case I denied it using! Empty (), that is, if it is not empty, then it will do so already checked the 3 together, because I believe you want to update only when the 3 are not empty ... And about textarea, I believe it would be the same logic. And about being a beginner in PHP, the beginning is just the same, when you see you will already be doing everything and correcting any errors that may arise ... Hugs, any doubts comment there.

    
25.05.2016 / 04:34
0

I'm editing and answering my own question with the code working.

<?php 
@session_start(); // Inicia a session.
if(!isset($_SESSION['rede_sociais'])){ 
// Se a Session não existir eu crio...
$face_status = 'Sim'; // Carrega esse conteúdo

//Armazena os dados na sessão que pode ser bidimensiona(array)
$_SESSION['rede_sociais']['face_status']=$face_status;

}else if(isset($_SESSION['rede_sociais'])){

// Se existir sessão, eu crio aqui
    $face_status = $_SESSION['rede_sociais']["face_status"];
}

<?php
//pega o valor do botao
$botao=$_POST['face'];
//verifica se o botao foi clicado
if($botao=="Atualizar"){
$face_status = $_POST["face_status"];
if(!empty($face_status)) {
$_SESSION['rede_sociais']["face_status"] = $face_status ;

echo "<meta http-equiv='refresh' content='0; URL= cabe_rede_sociais.php'>
<script language='javascript'>
    window.alert('Dados atualizados com sucesso!');
</script>";

}}
?>

<form method="post">
<label>Habilitar o Link do FaceBook?</label><br><br>
<input type='radio' name='face_status' value='Sim' checked="checked"/><label>Sim</label>
<input type="radio" name="face_status" value='Não'><label>Não</label>
<input type="submit" name="face" value="Atualizar">
</form>

I hope it helps other friends with the same problem of recording in SESSION using radio buttons.

A big hug to everyone.

    
28.05.2016 / 16:05
0

Problem solved with your friend Miguel's help, as POST

Below code working:

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

if(isset($_POST['status_prod']) && ($_POST['status_prod']) == 0) { // Desabilita o Botão.
    $link_prod = null;
    $status_prod = 'Não';
}else{
    $_POST['status_prod'] == 1; // Habilita o Botão com o Link de destino.
        $link_prod = '<li><a href="'.$end.'prod_index.php" class="nav1">'.$bot_prod.'</a></li><li class="divider"></li>';
        $status_prod = 'Sim';
        }
        $_SESSION['hab_prod']['status_prod'] = $status_prod;
        $_SESSION['hab_prod']['link_prod'] = $link_prod;

        echo "<meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
        <script language='javascript'>
        window.alert('Dados atualizados com sucesso!');
        </script>";
        }
?>
        <form method="post">
            <label>Habilitar o Link <?php echo $bot_prod ?>?</label><br><br>
            <input type='radio' name='status_prod' value='1' checked="checked"/><label>Sim</label>
            <input type='radio' name='status_prod' value='0'/><label>Não</label>
            <input type="submit" value="Atualizar">
        </form>

Hugs to all.

    
02.06.2016 / 17:26