greetings what I want is that I add the fields of quantity and income and be able to store the result in my database

0

this is my code

<?php
include ("conexion.php");

if(isset($_POST['btnagregar'])){
    $codigo=$_POST['codigo'];
  $cantidad=$_POST['cantidad'];
    $ingreso=$_POST['ingreso'];

    $consulta=mysql_query("select from registro_producto where id_producto=$codigo");

  mysql_query("UPDATE registro_producto SET cantidad=$cantidad+$ingreso WHERE id_producto=$codigo");
    }

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ingreso</title>
<script type="text/javascript" src="js/suma.js"></script>

</head>

<body>

    <center>

      <p><strong>   Ingreso Producto </strong></p>

      <form action="" method="post">


<form action="" method="post" name="cargar" id="acargar">
<table width="47%" height="197" border="1" cellpadding="2" cellspacing="2">
 <tr>
    <td width="53%">Codigo:</td>
    <td width="47%">
 <input type="text" name="codigo" id="codigo"></td>

  </tr>
  <tr>
    <td width="53%">Cantidad:</td>
    <td width="47%">
 <input type="text" name="cantidad" id="cantidad"></td>

  </tr>
<tr>
    <td>Cantidad a ingresar:</td>
    <td><input type="text" name="ingreso" id="ingreso"></td>
    </tr>
    <td height="73" colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="btnagregar" id="btnagregar" value="Aceptar"> 
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="submit" name="btncancelar" id="btncancelar" value="cancelar"></td>
    </tr>
</table>


</form>
</div>
</center>

</body>

</html>
    
asked by Ronald Torres 27.05.2018 в 19:14
source

1 answer

0

Try modifying your PHP code like this:

<?php
include ("conexion.php");

if(isset($_POST['btnagregar'])){
  $codigo=$_POST['codigo'];
  $cantidad=$_POST['cantidad'];
  $ingreso=$_POST['ingreso'];
  $suma = $cantidad + $ingreso;

 $conexion = mysql_connect("localhost", "nombre_usuario", "contraseña") or die("No se pudo conectar: " . mysql_error());
mysql_selectdb("nombre_basedatos",$conexion) or die ("No se puede usar el servidor de base de datos : " . mysql_error());

  mysql_query("UPDATE registro_producto SET cantidad='$suma' WHERE id_producto='$codigo'", $conexion);

    }

?>

Do not forget to include the single quotes around $ sum and $ code.

    
answered by 27.05.2018 в 19:29