Soy nuevo en programar, estoy intentando hacer un formulario, en donde su función es actualizar solamente el precio del material correspondiente, en este caso hay un scrip para que se auto complemente el nombre del material y el código. ¿Cómo hago para que los datos del formularios se envíen y se actualicen por medio de la consulta SQL?
Codigo PHP del formulario a utilizar
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<script >
$(function() {
//autocomplete
$("#material_name").autocomplete({
source: "formularios/auto_completar_material2.php",
focus: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
// manually update the textbox
//$(this).val(ui.item.label);
},
select: function(event, ui) {
// prevent autocomplete from updating the textbox
event.preventDefault();
// manually update the textbox and hidden field
$(this).val(ui.item.label);
$("#codigo").val(ui.item.cod);
$("#cod").val(ui.item.cod);
$("#material").val(ui.item.cod);
$("#material_name").val(ui.item.label);
}
});
});
</script>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
?>
<input type="text" name="codigo" id="codigo" hidden/>
<table class="display" style=" background-color: #DCDCDC">
<thead>
<tr>
<th>
<br>
<label style='text-align: center; font-size: 125%'>Asignacion de precio</label>
<br>
<br>
</th>
</tr>
</thead>
<tbody >
<tr>
<td>
<form action="precio.php" method="POST">
<label >CODIGO:</label>
<input type="text" name="cod" id="cod" style=" width: 7%" readonly />
<input type="text" name="material_name" id="material_name" style=" width: 82%" />
<!--<a onclick="limpiar_txt()" class="boton" title="Limpiar Nombre"><-</a>-->
<br>
<br>
<label >PRECIO A ASIGNAR:</label>
<input type="number" name="precio_material" id="precio_material" style=" width: 15%" />
<input type="button" value="CONSULTAR" style=" float: right" />
<br>
<br>
</form>
</td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</body>
</html>
<?php
<?php
require 'conexion.php';
session_start();
$codigo = $_POST['cod'];
$precio = $_POST['precio_material'];
if (isset($_POST["asignar"]))
{
if ($codigo=="" || $precio=="")
{
echo "los campos son obligatorios";
}
else{
$sql=" UPDATE `movimientos`
SET `precio` = IF(`tipo_movimiento` = 'ENTRADA' , '$precio' , `precio`)
WHERE `codigo_material` = '$codigo' ";
}
?>
Consulta sql Como explicacion, en la tabla movimientos hay una columna llamada tipo_movimiento, se estaria actualizando el precio en la columna tipo_movimiento cada vez que se "ENTRADA"
Precio.php
UPDATE `movimientos`
SET `precio` = IF( `movimientos`.`tipo_movimiento` = 'ENTRADA' , $precio , `precio`)
WHERE `movimientos`.`codigo_material` = '$codigo'
<form action="???" method="???">
en el html?"ENTRADA"
tienes comillas dobles, que finalizan la cadena de la consulta y, seguramente, estás obteniendo un error de sintaxis. Cambia por comillas simples y prueba a ver si funciona. Lo mismo para el valor decodigo_material
.