Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/11/2012, 16:26
josuecasu
 
Fecha de Ingreso: septiembre-2012
Ubicación: Barreiro
Mensajes: 48
Antigüedad: 11 años, 7 meses
Puntos: 0
Pregunta Como puedo evitar que al actualizar se grabe otro registro

el problema es que tengo una ppagina de carrito de compras... y en esta al momento de aumentar o disminuir la cantidad del articulo se me guarda 2, 3, 4, 5 veces y si sigo haciendo lo mismo me sigue guardando en la base de datos repetidos,,, por fa ayuda con esto.... agradecido de antemano...

les dejo mi codigo....
Código PHP:
<html>
<title>Sistema de Inventario</title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="header">
<h1><center>SISTEMA DE CONTROL Y SEGUIMIENTO <br /><br /><br /> DE SUMINISTROS DE OFICINA</h1></center>
</div>  <br />
 <div id="top"> </div>
<div id="content">
<script language="javascript">
function fAgrega()
{
document.getElementById("Text2").value = document.getElementById("Text1").value;
}
</script>

<?php
session_start
();
                include(
"conexion/conexion.php");    
                
$usuario=  $_SESSION["user"];
                
    
?>

<center>
RESPONSABLE:<input type="hidden" name="nombres" >
<option > <?php echo "$usuario"  ;?></option>    



    <div id="derecha">
        <h1></h1>
    
        <div class='text-border'>
        <?php
                
                    
                    
            
if (isset($_GET['id']))
                
$id $_GET['id'];
            else
                
$id 1;
            
            if (isset(
$_GET['action']))
                
$action $_GET['action'];
            else
                
$action "empty";
    
    
            switch(
$action){
            
                case 
"add":
                    if(isset(
$_SESSION['carro'][$id]))
                        
$_SESSION['carro'][$id]++;
                    else
                        
$_SESSION['carro'][$id]=1;
                break;
                
                case 
"remove":
                    if(isset(
$_SESSION['carro'][$id]))
                    {
                        
$_SESSION['carro'][$id]--;
                        if(
$_SESSION['carro'][$id]==0)
                            unset(
$_SESSION['carro'][$id]);
                    }
                    
                break;
                case 
"removeProd":
                    if(isset(
$_SESSION['carro'][$id])){
                        unset(
$_SESSION['carro'][$id]);
                    }
                break;
                
                case 
"mostrar":
                    if(isset(
$_SESSION['carro'][$id])){
                        continue;
                    }
                break;
                
                case 
"empty":
                    unset(
$_SESSION['carro']);
                
                break;
                        
                
            }

            if(isset(
$_SESSION['carro'])){
             echo 
" <table border=0 cellspacing=5 cellpadding=5 width='700'>";
                
                
//Inicializamos el contador de productos seleccionados.
                
                
                
echo "<tr>";
                    echo 
"<td><b>cod. Producto</td>";
                    echo 
"<td><b>Productos</td>";
                    echo 
"<td><b>Cantidad</td>";
                    echo 
"<td><b>Accion</td>";
                    echo 
"<td colspan=2><b>Stock</td>";
                echo 
"</tr>";
                echo 
"<tr><td colspan=5><hr></td></tr>";
                
                    foreach(
$_SESSION['carro'] as $id => $x){
                    
                    
$resultado mysql_query("select idsuministros , nomsuministros, unidades, departamento FROM suministros, users WHERE idsuministros='$id'");
                    
$mifila mysql_fetch_array($resultado);
                    
$cod $mifila['idsuministros'];
                    
$producto $mifila['nomsuministros'];
                    
//acortamos el nombre del producto a 40 caracteres
                    
$producto substr($producto,0,40);
                    
$precio $mifila['unidades'];
                    
//Coste por art�culo seg�n la cantidad elegida
                    
$coste $precio $x;
                    
//Coste total del carro
                    
$fecha=date("y-m-d");
                    
$canti="cantidad";
                    
$estado="I";
                     
                    
//Contador del total de productos a�adidos al carro
                //    $Total = $Total + $x;

                    
?>
                    <tr>
                    <form action ="carro.php"  method="post" name="carro" id="carro">
                        
                    <td><input type="hidden" name="cod" size="1" >
                    <option > <?php echo "$cod" ;?> </option>
                        
                    <td><input type="hidden" name="produ" size="1" >
                    <option > <?php echo "$producto" ;?> </option>
                    
                    <td><input type="hidden" name="cantidad" id="cantidad" size="1"/>
                    <option > <?php echo "$x" ;?> </option>
                     
                    <td><input type="hidden" name="depar" >
                    <option > <?php echo "$depar"  ;?></option>
                    
                    <input type="hidden" name="estado" value=" <?php echo "$estado"  ;?>" >
                    
                    </form>
                    <td >
                                    
                    <?php
                 
                     
                    
echo"<a href='carro.php?id="$id ."&action=add'><img src='images/carrito/aumentar.png' stle='padding:0 0px 0 5px;' alt='Aumentar cantidad' /></a>";
                    if (
$x 0)
                        echo 
"<a href='carro.php?id="$id ."&action=remove'><img src='images/carrito/restar.png' alt='Reducir cantidad' ></a>";
                    else
                        echo 
"<a href='carro.php?id="$id ."&action=removeProd'><img src='images/carrito/eliminar.png' alt='Reducir cantidad' /></a></td>";
                    
                    echo 
"<td align='right'>  </td>";
                    echo 
"<td  style='margin-left:10px'>$coste Cant.";
                    echo 
"</tr>";
                    echo 
"";
                    }
                    

                
?>
<tr></tr>                

</table>
            
                <?php
            $xx
=mysql_query("insert into detallepedido  VALUES ('$id_pedido', '$fecha','$cod', '$producto','$x','$usuario', '$estado')",$con);        
                                            
                    
$xxx="update detallepedido set producto='$producto', cantidad='$x' where id_pedido= '$id_pedido'" ;
                    
$ac=mysql_query($xxx,$con);
                    
$resp=mysql_query($xx,$con);
                    
$state true;    
                                                                    
                                    
                }
                                
        
?>        
        
        <table width="200" border="0">
  <tr>
    <td> <a href="productos.php"><div class="regresar" title="Seguir con el Pedido"></td><font color='red'></font></div></div></td></div></a>
     <br>Seguir con el Pedido</br>
  </tr>
</table>
<script>
function abrir(URL){
window.open(URL,"",'width=800,height=800,left=320, top=200,toolbar=0,scrollbars=0,statusbar=0,menubar =0,resizable=0');
}
</script>

</BR>
        </div> <!-- Cierro text-border -->
    </div> <!-- Cierro derecha -->

<!------ para desactivar la tecla f5 en mozilla y ie. ----->
<head>
<script language="javascript">

document.onkeydown = function(){
if(window.event && window.event.keyCode == 116){
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505){
return false;
}
}
</script></head>   

<script language="javascript">
document.onkeydown = function(e)
{
if(e)
document.onkeypress = function(){return true;}

var evt = e?e:event;
if(evt.keyCode==116)
{
if(e)
document.onkeypress = function(){return false;}
else
{
evt.keyCode = 0;
evt.returnValue = false;
}
}

</script>

<div class="articles"></div>
</div>
<div id="bottom"> </div>
</div>
<div style="clear: both;"> </div>
</div>
<div id="footer"> Sistema de Control y Seguimiento de Sumunistros &copy; 

</div>