Hola buenas estoy haciendo una web donde refleja las existencias del almacén. Tengo 2 campos que son Exmplrs(Ejemplares), rtrr(Retirar).Mi problema es que no se como tengo que hacer para que un usuario meta una cantidad en retirar y al aceptar el campo ejemplares se actualice restando la cantidad que se acaba de retirar.
Si alguién me puede ayudar se lo agradecería ya que lo necesito para el trabajo
Saludos
Os dejo el código:
Código PHP
<?php require_once('Connections/prueba.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "listadotlf.php" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE existencias SET ano_pblccn=%s, ttlo=%s, isbn=%s, pdf=%s, exmplrs=%s, ttl=%s WHERE id=%s",
GetSQLValueString($_POST['ano_pblccn'], "int"),
GetSQLValueString($_POST['ttlo'], "text"),
GetSQLValueString($_POST['isbn'], "text"),
GetSQLValueString($_POST['pdf'], "text"),
GetSQLValueString($_POST['exmplrs'], "int"),
GetSQLValueString($_POST['ttl'], "int"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_prueba, $prueba);
$Result1 = mysql_query($updateSQL, $prueba) or die(mysql_error());
$updateGoTo = "listadotlf.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE existencias SET ano_pblccn=%s, ttlo=%s, isbn=%s, pdf=%s, exmplrs=%s, ttl=%s WHERE id=%s",
GetSQLValueString($_POST['ano_pblccn'], "int"),
GetSQLValueString($_POST['ttlo'], "text"),
GetSQLValueString($_POST['isbn'], "text"),
GetSQLValueString($_POST['pdf'], "text"),
GetSQLValueString($_POST['exmplrs'], "int"),
GetSQLValueString($_POST['ttl'], "int"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_prueba, $prueba);
$Result1 = mysql_query($updateSQL, $prueba) or die(mysql_error());
$updateGoTo = "listadotlf.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_prueba, $prueba);
$query_rs_existencias = "SELECT existencias.id, existencias.ano_pblccn, existencias.ttlo, existencias.isbn, existencias.pdf, existencias.exmplrs, existencias.ttl, existencias.rtrr FROM existencias ORDER BY existencias.ano_pblccn";
$rs_existencias = mysql_query($query_rs_existencias, $prueba) or die(mysql_error());
$row_rs_existencias = mysql_fetch_assoc($rs_existencias);
$totalRows_rs_existencias = mysql_num_rows($rs_existencias);
?>
<html>
<head>
<title>Listado Existencias do almacén</title>
</head>
<body>
<br><br><br><form name="form1" method = "GET" action = "buscador.php">
<strong><center align>Búsqueda na base de datos:</strong>
<input type="text" name="buscar" size="20">
<input type="submit" value="buscar">
</form></center>
<p> </p>
<p><strong>Insertar Novo rexistro </br>
<form method="POST" name="form" action="insertar2.php">
<table align="">
<tr valign="baseline">
<td nowrap align="right">Ano Publicación:</td>
<td><input type="text" name="ano_pblccn" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Título:</td>
<td><input type="text" name="ttlo" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Isbn:</td>
<td><input type="text" name="isbn" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Pdf:</td>
<td><input type="text" name="pdf" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Exenplares:</td>
<td><input type="text" name="exmplrs" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" name="accion" value="insertar"></td>
</tr>
</table>
</form>
</strong></p>
<?php do { ?>
<table align=center width="90%" border="1" STYLE="table-layout:fixed">
<tr>
<td align=center width="4%"><font size="2px"><?php echo $row_rs_existencias['ano_pblccn']; ?> </td>
<td align=center width="25%"><font size="2px"><?php echo $row_rs_existencias['ttlo']; ?></td>
<td align=center width="10%"><font size="2px"><?php echo $row_rs_existencias['isbn']; ?></td>
<td align=center width="3%"><font size="1"><?php echo $row_rs_existencias['pdf']; ?></td>
<td align=center width="1%"> <font size="2px"><div align="center"><a href="formulario.php?id= <?php echo $row_rs_existencias['id']; ?>"><img src="actualizar.jpg" width="23" height="20" border="0"></a></div></td>
<td align=center width="1%"> <font size="2px"><div align="center"> <script language="Javascript">
function preguntar(){
eliminar=confirm("¿Desexas eliminar este rexistro?");
if (eliminar)
//Redireccionamos si das a aceptar
window.location.href ="borra.php?id=%d"; //página web a la que te redirecciona si confirmas la eliminación
else
//Y aquí pon cualquier cosa que quieras que salga si le diste al boton de cancelar
alert('Non se ha puido eliminar o rexistro...')
}
</script>
<a href="javascript:preguntar()"><img src="papelera.jpg" width="23" height="20" border="0"> </a></div></td>
<td align=center width="3%"><font size="2px"><?php echo $row_rs_existencias['exmplrs']; ?></td>
<td align=center width="1%"><font size="2px"><?php echo $row_rs_existencias['rtrr']; ?></td>
<td align=center width="3%"><font size="2px"><?php echo $row_rs_existencias['ttl']; ?></td>
</size>
</tr>
</table>
<?php } while ($row_rs_existencias = mysql_fetch_assoc($rs_existencias)); ?>
<p> </p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs_existencias);
?>