Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/01/2010, 23:00
t00l
 
Fecha de Ingreso: enero-2010
Mensajes: 3
Antigüedad: 14 años, 3 meses
Puntos: 0
Problema restando dos campos!

Hola amigos, soy nuevo pero veo el foro constantemente. Tengo un problema que me gustaria porfavor si me pudieron ayudar a solucionarlo.

Tengo un formulario super simple:

Código:
<html>
<body>

<FORM METHOD="POST" ACTION="procesar2.php">
<table align="left" border="0">
    <td align="left" width="115" >Nombre Chofer</td>
    <td align="center" width="150"><INPUT NAME="nomchofer" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Rut Chofer</td>
    <td align="center" width="150"><INPUT NAME="rutchofer" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Patente Camion</td>
    <td align="center" width="150"><INPUT NAME="pacamion" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Patente Carro</td>
    <td align="center" width="150"><INPUT NAME="pacarro" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Transporte</td>
    <td align="center" width="150"><INPUT NAME="transpor" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Tara</td>
    <td align="center" width="150"><INPUT NAME="tara" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Peso Bruto</td>
    <td align="center" width="150"><INPUT NAME="bruto" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Hora Llegada</td>
    <td align="center" width="150"><INPUT NAME="horalle" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>
<tr>
    <td align="left" width="115">Hora Salida</td>
    <td align="center" width="150"><INPUT NAME="horasa" MAXLENGTH="25" TYPE="TEXT" VALUE=""></td>

<tr>
    <td widht="115"><input name="Reset" type="RESET" Value="Reset"></td>
    <td align="right" width="150"><INPUT NAME="boton" TYPE="SUBMIT" VALUE="Grabar"></td>
</TABLE>
</form>
</body>
</html>
y su proceso:

Código:
<?php
$con = mysql_connect("localhost","root","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("empresa", $con);

$tara = $_POST[tara] ;
$bruto = $_POST[bruto] ;
$neto = $bruto - $tara ;


$sql="INSERT INTO ingresos (nomchofer,rutchofer,pacamion,pacarro,transpor,tara,bruto,horalle,horasa,neto)
VALUES
('$_POST[nomchofer]','$_POST[rutchofer]','$_POST[pacamion]','$_POST[pacarro]','$_POST[transpor]','$_POST[tara]','$_POST[bruto]','$_POST[horalle]','$_POST[horasa]','$neto')"

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
//echo "1 record added";

mysql_close($con);


header("Location: prueba1.php");


?>
Lo que tengo que hacer es poder restar los campos "bruto" y tara" y guardarlo en el campo "neto" que esta creado en la bd.
Esta operacion debe hacerse cada vez envio algun formulario, y debe ser guardado automaticamente en la bd.
Por favor! he intentado de todo pero sin frutos, ojala me ayuden. Gracias de antemano!

Me manda este error:

Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\palma\procesar2.php on line 20

Última edición por t00l; 11/01/2010 a las 23:58 Razón: update