Jump to content

Duvida ao gravar sessao!


silvamouro
 Share

Recommended Posts

Imaginemos que eu quero Fazer 3 Etapas:

Index.php

<form id="form1" name="form1" method="post" action="passo1.php">
  <table width="200" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="65">Nome:</td>
      <td width="135"><label>
        <input name="nome" type="text" id="nome" value="<?=$_SESSION['nome'];?>" />
      </label></td>
    </tr>
    <tr>
      <td>Idade:</td>
      <td><input name="idade" type="text" id="idade" value="<?=$_SESSION['idade'];?>" /></td>
    </tr>
    <tr>
      <td></td>
      <td><label>
        <input type="submit" name="button" id="button" value="Enviar" />
      </label></td>
    </tr>
  </table>
</form>

Passo1.php

<?
session_start();
$nome = $_POST['nome'];
$_SESSION["nome"]	= "$nome";
$idade = $_POST['idade'];
$_SESSION["idade"]	= "$idade";
?>
<form name="form1" method="post" action="passo2.php">
  <table width="498" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="68">Profissão</td>
      <td width="430"><label>
        <input name="profissao" type="text" id="profissao" value="<?=$_SESSION['profissao'];?>">
      </label></td>
    </tr>
    
    <tr>
      <td> </td>
      <td><label>
        <INPUT  id="btVoltar" onClick="javascript:window.location='index.php';" type="button" value="Anterior" name="btVoltar">
        <input type="submit" name="button" id="button" value="seguinte">
      </label></td>
    </tr>
  </table>
</form>

Passo2.php

<?

$profissao = $_POST['$profissao'];
$_SESSION["profissao"]	= "$profissao";

?>
<form name="form1" method="post" action="passo2.php">
  <table width="498" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="68">Morada</td>
      <td width="430"><label>
        <input name="morada" type="text" id="profissao" value="<?=$_SESSION['morada'];?>">
      </label></td>
    </tr>
    
    <tr>
      <td> </td>
      <td><label>
        <INPUT  id="btVoltar" onClick="javascript:window.location='passo1.php';" type="button" value="Anterior" name="btVoltar">
        <input type="submit" name="button" id="button" value="seguinte">
      </label></td>
    </tr>
  </table>
</form>

No index é um formulario contem os campos nome e idade, avanço para o passo1 onde inicio a sessa0 e grava-me os dados recebidos  por post neste caso o nome e a idade, depois tenho o formulario que vou inserir a profissao e passo para o passo2.php onde ele grava o que recebeu do passo 1 que foi a profissao, mas acontece que se eu clicar no botao "anterior" ele vai voltar ao passo1.php e vai gravar nome e a idade como se fosse vazio como poço fazer para que isso não aconteça?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.