Binary Road
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Auto peças

Ir para baixo

Auto peças Empty Auto peças

Mensagem  Renancr Dom 13 Mar 2011 - 14:09

Primeiras tentativas de PHP


index.html
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto peças Caramuru</title>
</head>

<body>
<p align="center"><font color="#000000" size="6"><b>Auto peças Caramuru</b></font></p>
<p align="center">&nbsp;</p>
<p align="center"><font color="#000000" size="5"><b>Ordem de pedido</b></font></p>
<form action="processopedido.php" method="post">
<table width="200" border="0" align="center">
  <tr bgcolor="#CCCCCC">
    <td width="136">Item</td>
    <td width="54">Quantidade</td>
  </tr>
  <tr>
    <td>Pneus</td>
    <td align="center"><input type="text" name="pneusqt" size="3" maxlength="3" value="0"/>&nbsp;</td>
  </tr>
  <tr>
    <td>Ólio</td>
    <td align="center"><input type="text" name="olioqt" size="3" maxlength="3" value="0" />&nbsp;</td>
  </tr>
  <tr>
    <td>Velas</td>
    <td align="center"><input type="text" name="velaqt" size="3" maxlength="3" value="0"/>&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" align="center"><input type="submit" value="Confirmar Pedido" /></td>
  </tr>
</table>

</form>
</body>
</html>

processopedido.php
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto peças Caramuru - Resultado do pedio</title>
</head>

<body>
<h1 align="center"><font color="#000000" size="6"><b>Auto peças Caramuru</b></font></h1>
<h2 align="center"><font color="#000000" size="5"><b>Resultado do Pedido</b></font></h2>
<?php
echo '<p align="center"><font color="green">Pedido Processado em ';
echo date('H:i, jS F');
echo '</font></p>';
?>
<?php
$totalqt=0;
$totalqt=$totalqt+$_REQUEST['pneusqt'];
$totalqt=$totalqt+$_REQUEST['olioqt'];
$totalqt=$totalqt+$_REQUEST['velaqt'];
echo '<p align="center">Seu pedido segue como:</p>';
echo '<p align="center">';
echo $_REQUEST['pneusqt'].' Pneus
';
echo $_REQUEST['olioqt'].' Olio
';
echo $_REQUEST['velaqt'].' Vela
';
echo 'Quantidade total = '.$totalqt.'
';
echo '</p>';
?>
</body>
</html>

processopedido.php 2.0
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto peças Caramuru - Resultado do pedio</title>
</head>

<body>
<h1 align="center"><font color="#000000" size="6"><b>Auto peças Caramuru</b></font></h1>
<h2 align="center"><font color="#000000" size="5"><b>Resultado do Pedido</b></font></h2>
<?php
echo '<p align="center"><font color="green">Pedido Processado em ';
echo date('H:i, jS F');
echo '</font></p>';
?>
<?php
$totalqt=0;
$totalqt=$totalqt+$_REQUEST['pneusqt'];
$totalqt=$totalqt+$_REQUEST['olioqt'];
$totalqt=$totalqt+$_REQUEST['velaqt'];
define('PRPNEUS', 140.00);
define('PROLIO', 25.00);
define('PRVELA', 5.00);
$prtotal=0.00;
$prtotal=(double)$prtotal+$_REQUEST['pneusqt']*PRPNEUS;
$prtotal=(double)$prtotal+$_REQUEST['olioqt']*PROLIO;
$prtotal=(double)$prtotal+$_REQUEST['velaqt']*PRVELA;
echo '<p align="center">Seu pedido segue como:</p>';
echo '<table width="296" border="0" align="center">
  <tr bgcolor="#CCCCCC">
    <td width="136">Item</td>
    <td width="80">Quantidade</td>
    <td width="80">Valor</td>
  </tr>
</table>
';

echo '<table width="296" border="0" align="center">
  <tr>
    <td width="136">Peneus</td>';
echo '<td width="80">'.$_REQUEST['pneusqt'].'</td>';
echo '<td width="80">R$ '.PRPNEUS.'</td>';
echo '</tr>
</table>';

echo '<table width="296" border="0" align="center">
  <tr>
    <td width="136">Olio</td>';
echo '<td width="80">'.$_REQUEST['olioqt'].'</td>';
echo '<td width="80">R$ '.PROLIO.'</td>';
echo '</tr>
</table>';

echo '<table width="296" border="0" align="center">
  <tr>
    <td width="136">Vela</td>';
echo '<td width="80">'.$_REQUEST['velaqt'].'</td>';
echo '<td width="80">R$ '.PRVELA.'</td>';
echo '</tr>
</table>';

echo '<table width="296" border="0" align="center">
  <tr bgcolor="#CCCCCC">
    <td width="136"></td>
    <td width="80">Total</td>
    <td width="80">Total</td>
  </tr>
</table>
';
echo '<table width="296" border="0" align="center">
  <tr>
    <td width="136"></td>';
echo '<td width="80">'.$totalqt.'</td>';
echo '<td width="80">R$ '.$prtotal.'</td>';
echo '</tr>
</table>';
?>
</body>
</html>

processopedido.php 2.5 Adicionado if e else
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auto peças Caramuru - Resultado do pedio</title>
</head>

<body>
<h1 align="center"><font color="#000000" size="6"><b>Auto peças Caramuru</b></font></h1>
<h2 align="center"><font color="#000000" size="5"><b>Resultado do Pedido</b></font></h2>
<?php
if($_REQUEST['pneusqt'] > 0 && $_REQUEST['olioqt'] > 0 && $_REQUEST['velaqt'] > 0)
{
   echo '<p align="center"><font color="green">Pedido Processado em ';
   echo date('H:i, jS F');
   echo '</font></p>';

   define('PRPNEUS', 140.00);
   define('PROLIO', 25.00);
   define('PRVELA', 5.00);

   $totalqt=0;
   $prtotal=0.00;

   echo '<p align="center">Seu pedido segue como:</p>';
   echo '<table width="296" border="0" align="center">
     <tr bgcolor="#CCCCCC">
      <td width="136">Item</td>
      <td width="80">Quantidade</td>
      <td width="80">Valor</td>
     </tr>
   </table>
   ';

   if($_REQUEST['pneusqt'] > 0)
   {
      $totalqt=$totalqt+$_REQUEST['pneusqt'];
      $prtotal=(double)$prtotal+$_REQUEST['pneusqt']*PRPNEUS;
      echo '<table width="296" border="0" align="center">
        <tr>
             <td width="136">Peneus</td>';
      echo '<td width="80">'.$_REQUEST['pneusqt'].'</td>';
      echo '<td width="80">R$ '.PRPNEUS.'</td>';
      echo '</tr>
      </table>';
   }
   if($_REQUEST['olioqt'] > 0)
   {
      $totalqt=$totalqt+$_REQUEST['olioqt'];
      $prtotal=(double)$prtotal+$_REQUEST['olioqt']*PROLIO;
      echo '<table width="296" border="0" align="center">
        <tr>
          <td width="136">Olio</td>';
      echo '<td width="80">'.$_REQUEST['olioqt'].'</td>';
      echo '<td width="80">R$ '.PROLIO.'</td>';
      echo '</tr>
      </table>';
   }
   if($_REQUEST['velaqt'] > 0)
   {
      $totalqt=$totalqt+$_REQUEST['velaqt'];
      $prtotal=(double)$prtotal+$_REQUEST['velaqt']*PRVELA;
      echo '<table width="296" border="0" align="center">
        <tr>
         <td width="136">Vela</td>';
      echo '<td width="80">'.$_REQUEST['velaqt'].'</td>';
      echo '<td width="80">R$ '.PRVELA.'</td>';
      echo '</tr>
      </table>';
   }

   echo '<table width="296" border="0" align="center">
     <tr bgcolor="#CCCCCC">
       <td width="136"></td>
       <td width="80">Total</td>
       <td width="80">Total</td>
     </tr>
   </table>
   ';
   echo '<table width="296" border="0" align="center">
     <tr>
      <td width="136"></td>';
   echo '<td width="80">'.$totalqt.'</td>';
   echo '<td width="80">R$ '.$prtotal.'</td>';
   echo '</tr>
   </table>';
}
else
{
   echo '<p align="center"><font size="5" color="red"><b>O pedido nao pode ser realizado pois nem uma quantidade foi determinada</b></font>';
}
?>
</body>
</html>
Renancr
Renancr

Mensagens : 118
Data de inscrição : 08/03/2010

Ir para o topo Ir para baixo

Ir para o topo


 
Permissões neste sub-fórum
Não podes responder a tópicos