PHP upgrade in stock

Asked

Viewed 239 times

2

I would like to take the amount used and whether or not the person received and update in mysql.

inserir a descrição da imagem aqui

<html>
<title>Produtos da OS <?php echo $id; ?></title>
<script language='JavaScript'>
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla>47 && tecla<58)) return true;
    else{
        if (tecla==8 || tecla==0) return true;
    else  return false;
    }
}
</script>
</html>
<?php
include('config.php');
  $ip = $_SERVER['REMOTE_ADDR'];
  $usuario = $_POST['usuario'];
  $senha = $_POST['senha'];
  $id = $_POST['id'];
  $resolucao = $_POST['historico'];
  $ip1 = $_POST['ip1'];
  $ip2 = $_POST['ip2'];
  $veiculo = $_POST['automovel'];
  mysql_query("INSERT INTO `os_ip` (`cod_ip`,`ip1`,`ip2`,`os_id`) VALUES (NULL,'".$ip1."','".$ip2."','".$id."');");
  echo "<BR><BR><BR>";
  if(empty($usuario)){
    echo ("<center><h2><font color=red>Campo usu&aacute;rio esta em branco, favor preencher!");
  } else {
    if(empty($senha)){
    echo ("<center><h2><font color=red>Campo senha esta em branco, favor preencher!");
  } else {
    if(empty($id)){
    echo ("<center><h2><font color=red>Campo n&#186; OS esta em branco, favor preencher!");
  } else {
  $tes = mysql_query("select count(*) from os where id ='$id'");
  $tes1 = mysql_result($tes,0);
  if ($tes1==1){
  $os = mysql_query("select status from os where id='$id'");
  $os1 = mysql_result($os,0);
  $us = mysql_query("select count(*) from user where user='$usuario' and user_password='$senha'");
  $use1 = mysql_result($us,0);
  if (($os1==1)or ($os1==3)) {
  mysql_query("UPDATE os SET status=3, resolucao='$resolucao'  where id = $id");
  if ($use1 == 1) {
  if (empty($veiculo)) {
    echo ("<center><h2><font color=red>Ve&iacute;culo n&atilde;o foi selecionado!");
  } else {
  $query2 = mysql_query('SELECT nome FROM automoveis where id='.$veiculo.'');
  $auto = mysql_result($query2,0);
  $clien = mysql_query('SELECT nome_cliente FROM os where id='.$id.'');
  $cliente = mysql_result($clien,0);
  $usern = mysql_query('SELECT clientes_id FROM os where id='.$id.'');
  $username = mysql_result($usern,0);
  echo "<form action='fechaos.php' method=post>
      <table border='0' align=center width=700>
        <tr>
          <td>Usu&aacute;rio: <b>". $usuario ."</b></td>
          <td>IP: ". $ip ."</td>
        </tr>
        <tr>
          <td>OS n&#186;: <b>". $id ."</b></td>
          <td>Ve&iacute;culo: <b>". $auto."</b></td>
        </tr>
        <tr>
          <td>Cliente: <b>".$cliente."</b></td>
          <td><input type='hidden' name='id2' value=".$id ." /></td>
        </tr>
      </table>";
$res = mysql_query("select * from produtos ORDER BY nome ASC"); /*Executa o comando SQL, no caso para pegar todos os usuarios do sistema e retorna o valor da consulta em uma variavel ($res)  */
echo "<table border='1' align=center width=700>
        <tr>
          <td align=center width=540><b>Nome</b></td>
          <td align=center width=100><b>Valor</b></td>
          <td align=center width=30><b>Quantidade<BR>Utilizada</b></td>
          <td align=center width=30><b>Recebeu?</b></td>

        </tr>";
/*Enquanto houver dados na tabela para serem mostrados será executado tudo que esta dentro do while */
while($escrever=mysql_fetch_array($res)){

/*Escreve cada linha da tabela*/
$num = $escrever['valor'];
$num1 =  number_format($num, 2, ',', '.');
$prod6 = $escrever['id'];

echo "<tr>
        <td align=center>" . $escrever['nome'] . "</td>
        <td align=center>R$ " . $num1 . "</td>
        <td align=center><input type='text' size='10' name='quant' maxlength='3' onkeypress='return SomenteNumero(event)'></td>
        <td  align=center><select size='1'>
          <option selected></option>
          <option value='p_sim'>Sim</option>
          <option value='p_nao'>Não</option>
          <option value='p_loja'>Loja</option>
          <option value='p_repo'>Reposição</option>
          </select>
          <input name='id_prod' type='hidden' value=". $escrever['id'] .">
        </td>
      </tr>
      <input type='hidden' name='produ1' value=".$prod6 ." />";
}/*Fim do while*/
echo "</table>
<table border=0 align=center>
<tr>
  <td><BR><input type='submit' value='Finalizar OS'></td>
</tr>
</table>

</form>"; /*fecha a tabela apos termino de impressão das linhas*/
}
} else {
  echo "<font color=red><center>Usu&aacute;rio ou senha errados ou n&atilde;o esta autorizado!</font>";
}
} else {
  echo "<center><h1><font color=red>OS j&aacute; foi finalizada, favor informar ao Leo, para verificação!";
}
}else{
  echo ("<center><h1><font color=red>OS n&atilde;o encontrada!");
}
}
}
}
?>

This is the 'closed.php' pag'

<?php
include('config.php');
  $quant = $_POST['quant'];
  $id = $_POST['id2'];
  $produto = $_POST['id_prod'];


  echo $quant, $id, $produto;
  mysql_query("UPDATE os SET status=0 where id = $id");
  mysql_query("INSERT INTO `estoque` (`produtos_id`,`cc`,`quant`) VALUES ('".$produto."','0','".$quant."');");

Someone could help me?

  • You either put your table inside a form or manipulate it with javascript?

  • she is in the form with while

  • What you should not be able to do is have the information of selects because they have no name.

  • You should not repeat Ames so I advise you to implode anything like name="name_$write[id]"

  • If you are using echo "" you do not need to echo "text". $variable." text"; just echo "text $variable text"; is the big difference between "" and '' in php

  • Can you further detail the embarrassment? It was clear what the goal is but not specified the embarrassment.

Show 1 more comment

1 answer

0

You must generate the Names dynamically

Create a variable and increment it with each iteration, so you can create field-1, field-2, field-3...

ex:

<?php
  $i = 1;
  echo '<form>';
  while(condicao){
     echo "<input type='text' name='campo-".$i."'>";
     echo "<select name='combo-".$i."'>";
         echo "<option value='op1'>Opcao 1</option>";
         echo "<option value='op2'>Opcao 2</option>";
     echo "</select>";
     i++;
  }
  echo '</form>';
?>

From there it is very simple to receive from the other side

  • It should not be $i if you want to write to the database (update) but id to be able to identify them. If you are using "" in my opinion you should not use ". $i." because php already checks variables be ""

  • @Thiagogomes in the case is only separating the fields with sequential numerical identifiers. Even the field that will receive the product ID would also be sequenced. The idea is, every field closed with 1 refers to a product, 2 to another product, and assiduously. It will not interfere with the valoar the ID will simply simplify and organize the processing of the page. So it can work as you like, separate each product in an array before saving or defining an array for quantity and other options, it is very flexible and easy to work with.

  • It’s just an opinion. When there is a database behind it the reference should be the id and not a sequential number. To be easy to identify. Especially when this data does not exist in the table itself.

Browser other questions tagged

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