How to treat select by client ID between two PHP pages

Asked

Viewed 444 times

1

Personal when I select a client and after that I enter in the page of their crediarios and having perform new registration crediario the ID of this client is lost, how can I treat this?

file to select clients -> clients.php

<div id="painelcadastro2">
<div align="center">
<?php
$sql = "SELECT Ficha, Snome FROM t_cadclientes ORDER BY Ficha ASC, Snome ASC";
$resultado = mysql_query($sql)
            or die (mysql_error());
if(@mysql_num_rows($resultado) == 0)
            echo ("Cliente não encontrado(a) !");
?>

<form id="form2" name="form2" method"post" action="" enctype="multipart/form-data">
<div align="center">
  <table border="0" align="center">
      <tr>
        <td><label>
          <select name="id" id="id">
            <option value="-1" selected="selected">Selecione um cliente</option>
            <?php 
    while($linha=mysql_fetch_array($resultado)) {
        $id = $linha[0];
        $Snome = $linha[1];
?>
            <option value="<?php echo $id;?>"><?php echo $Snome;  ?></option>
<?php
    }
?>
          </select>
          </label></td>
          <tr>
        <label>
          <input type=image src="../images/vendas_crediarioOver.png" onMouseOver="this.src='../images/vendas_crediario.png'" onMouseOut="this.src='../images/vendas_crediarioOver.png'" title="Venda Crediário" style="border:0;" name="vendas_crediario" id="vendas_crediario" value="vendas_crediario" formaction="vendas_crediario.php" />
          </label>
      </tr>
</table>
</form>

file where I check the crediarios of this client and can add a new -> vendas_crediario.php

    <div id="painelcadastro">
    <div align="center">
    <?php
    $Ficha = $_GET['id'];
    $selecionacliente = mysql_query("SELECT Ficha, Snome FROM t_cadclientes WHERE Ficha = '$Ficha'");
      if($selecionacliente == ''){
        echo "Erro ao Selecionar, tente novamente !";
      }else{  
        while($res_idcliente = mysql_fetch_array($selecionacliente)){
        $id = $res_idcliente['Ficha'];
        $Snome = $res_idcliente['Snome'];
    ?> 
    <br /><br />

    Ficha Número: <?php echo $Ficha ?><br />
    Nome do Cliente: <?php echo $Snome?>
    <br /><br />

             <?php
    $sql = "SELECT NumContrato, DataContrato FROM t_cadcontratos WHERE Ficha = '$Ficha'";
    $resultadocontratos = mysql_query($sql)
          or die (mysql_error());
    if(@mysql_num_rows($resultadocontratos) == 0)
          echo ("Este cliente não possui contratos !");
    ?><br />
    <form id="form2" name="form2" method"post" action="" enctype="multipart/form-data">
    <div align="center">
      <table border="0" align="center">
          <tr>
            <td><label>
              <select name="id" id="id">
                <option value="-1" selected="selected">Selecione um contrato</option>
                <?php 
      while($linha=mysql_fetch_array($resultadocontratos)) {
        $NumContrato = $linha[0];
        $DataContrato = $linha[1];
    ?>
                <option value="<?php echo $NumContrato;?>">Contrato: <?php echo $NumContrato;?> | Data da Compra: <?php echo date("d/m/Y", strtotime($DataContrato));?></option> <br /><br />
    <?php
      }
    ?>        
     </select>
              </label></td>
              <tr>
            <label>
              <input type="hidden" name="apaga" value="delete" />
              <input type=image src="../images/excluirOver.png" onMouseOver="this.src='../images/excluir.png'" onMouseOut="this.src='../images/excluirOver.png'" title="Excluir Contrato" style="border:0;" name="delete" id="delete" value="Excluir" />
              <input type=image src="../images/editarOver.png" onMouseOver="this.src='../images/editar.png'" onMouseOut="this.src='../images/editarOver.png'" title="Editar Contrato" style="border:0;" name="Alterar" id="Alterar" value="Alterar" formaction="editar_contrato.php" />
              <input type=image src="../images/imprimirOver.png" onMouseOver="this.src='../images/imprimir.png'" onMouseOut="this.src='../images/imprimirOver.png'" title="Imprimir Contrato" style="border:0;" name="Imprimir" id="Imprimir" value="Imprimir"  formaction="imprimir_contrato.php" />
              </label>
          </tr>
</table><td>
 <?php
  }
}
?>
<input type=image src="../images/cadastrarOver.png" onMouseOver="this.src='../images/cadastrar.png'" value="<?php echo $id?>" onMouseOut="this.src='../images/cadastrarOver.png'" title="Cadastrar" style="border:0;" name="cadastro" id="cadastro" value="cadastro"  formaction="cadastro_contrato.php" />
</div><!--fechando div painelcadastro-->

file to add crediario to the client -> cadastro_crediario.php

Record Number:

<div id="painelcadastro2" align="center">
<?php   if (isset($_GET['cadastra']) && $_GET['cadastra'] == 'add') {
  $datacompra = implode("-", array_reverse(explode("/",$_GET['datacompra'])));
  $nomeProduto = filter_input(INPUT_POST, 'nomeProduto1');
  $qtProduto = filter_input(INPUT_POST, 'qtProduto1');
  $valorProduto = filter_input(INPUT_POST, 'valorProduto1');
  $parcelas = filter_input(INPUT_POST, 'select_parcelas');
  $entrada = filter_input(INPUT_POST, 'entrada');
  $total = filter_input(INPUT_POST, 'total');
  $pagamento = "CREDIARIO";
  $ficha = $_GET['cadastro'];
  $cadastra = mysql_query("INSERT INTO t_cadcontratos (Ficha, NumContrato,DataContrato, QuantParcelas, ValorContrato, Entrada, Saldo, DescricaoProduto, QuantProdutos, FormaPagamento) 
                          VALUES ('$ficha', '$datacompra', '$parcelas', '$valorProduto', '$entrada', '$total', UPPER('$nomeProduto'), '$qtProduto', '$pagamento')");
  if($cadastra == '1') {
        echo "Venda Crediário realizada com sucesso !";
  }else{
        echo "Erro ao realizar a venda Crediário, tente novamente !";
  }
}
?>

By clicking register in the form that does not insert here the value of $_GET['registration']; that would be the client’s ID is lost at the time of insertion in the database.

1 answer

3

Dude, I don’t know if I got it right, but it looks like you want to send the client ID from the "vendas_crediario.php" page to "cadastro_crediario.php". If so, just create an Hidden input containing the client’s id. It would look something like this:

<input type="hidden" value="<?php echo $Ficha?>" name="cadastro" />
  • is exactly that, remembering that already brought the client ID from another page, I’m sorry I missed the end of the page vendas_crediario that would be the separate button to send the ID <input type=image src=".. /images/registersOver.png" onMouseOver="this.src='.. /images/cadastrar.png'" value="<? php echo $id? >" onMouseOut="this.src='.. /images/registrationOver.png'" title="Register" style="border:0;" name="register" id="register" value="register" formaction="register.php" />

  • Passing the ID this way I can print the value normally, but when I will add in the BD after filling the fields I lose this variable, have any idea?

Browser other questions tagged

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