Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/09/2012, 18:03
faseb
 
Fecha de Ingreso: septiembre-2012
Ubicación: posadas
Mensajes: 53
Antigüedad: 11 años, 7 meses
Puntos: 0
no me guarda la consulta

hola como andan..
tengo una bd y un programa en php desde el cual quiero hacer una insercion a dicha bd a traves de una consulta. la insercion deberia realizarse luego de presionar un boton pero no lo hace..
a continuacion el codigo que tengo no se que es lo que pasa.

<?php
require('conexion.php');

session_start();

$bandera=0;
$fecha=date("Y - m - d");

if (!isset($_SESSION['nick'])) {
header("Location: /login.php");exit();
};

$ped=mysql_query('
select MAX(N_PEDIDO)
from ventas');
$ped_=mysql_fetch_row($ped);
$n_ped=++$ped_[0];


if ($bandera){
$bandera = 0;


$consulta=mysql_query('insert into ventas (N_PEDIDO, COD_CLI, COD_EMP, COD_PROD, FECHA_PEDIDO, CANTIDAD, PRECIO, SUBTOTAL) values ("'.$n_ped.'","'.$_POST['COD_CLI'].'","'.$_SESSION["clave"].'","'.$_POST['ID_PROD'].'","'.$fecha.'","'.$_POST['CANTIDAD'].'","'.$_POST['PRECIO'].'","'.$_POST['SUBTOTAL'].'")');

echo 'Se agregó el registro<BR>';

}else{

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>VENTAS</title>
</head>
<script language="JavaScript" type="text/javascript" src="/ajax.js"></script>

<script>
function calcula(operacion){
var cantidad = document.carga.CANTIDAD.value
var precio = document.carga.PRECIO.value
var subtotal = cantidad * precio
document.carga.SUBTOTAL.value = subtotal
}

function suma (operacion){
var subtotal = document.carga.SUBTOTAL.value
var total = document.carga.TOTAL.value
var calc = eval(subtotal + operacion + total)
document.carga.TOTAL.value = calc
}
</script>

<body>

<form name="carga" action="/index.php" method="post">
<table width="832" border="0">
<tr>
<td width="50">Fecha:</td>
<td width="100"><?php echo $fecha ?></td>
<td width="500">&nbsp;</td>
<td width="80">Empleado:</td>
<td width="80"><?php echo $_SESSION["nick"] ?></td>
<td width="50"><?php echo '<p><a href="logout.php">Salir</a></p>'?></td>
</tr>
</table>
<br>
<br>
<tr>
<td width="70">CLIENTE:</td>
</tr>
<BR>
<table width="227" border="0">
<tr>
<td width="76">Documento:</td>
<td width="141"><input name="COD_CLI" type="text" value="" onBlur="MostrarConsulta(this.value);"/></td>
<div id="dinamico"></div>
</tr>
</table>
<br>
<br>
<table width="170" border="0">
<tr>
<td width="110">Pedido Numero:</td>
<td width="50"><?php echo $n_ped ?></td>
</tr>
</table>

<br>
<table width="520" border="0">
<tr>
<td width="60">Producto:</td>
<td width="4">&nbsp;</td>
<td width="144">Cantidad:</td>
<td width="4">&nbsp;</td>
<td width="144">Unitario:</td>
<td width="4">&nbsp;</td>
<td width="4">&nbsp;</td>
<td width="56">Subtotal:</td>
</tr>
<tr>
<td><select name="ID_PROD"><?php
$temp=mysql_query('
select COD_PROD, DESCRIPCION
from productos
order by DESCRIPCION');
while ($temp_=mysql_fetch_row($temp)){
echo '<option value="'.$temp_[0].'">'.$temp_[1].'
</option>';} ?></select></td>
<td>&nbsp;</td>
<td><input name="CANTIDAD" type="text" ></td>
<td>&nbsp;</td>
<td><input name="PRECIO" type="text"></td>
<td>&nbsp;</td>
<td><input type="Button" name="" value=" X " onClick="calcula('*')"></td>
<td><input type="text" name="SUBTOTAL" value="0"></td>
<td width="11">&nbsp;</td>
<td width="55"><input name="guardar" type="submit" value="Grabar" />
</td>
</tr>
</table>
<br>
<table width="510" border="0">
<tr>
<td width="336">&nbsp;</td>
<td><input type="Button" name="" value=" + " onClick="suma('+')"></td>
<td width="80">Total:</td>
<td width="80"><input type="text" name="TOTAL" value="0"></td>
</tr>
</table>
<?php $bandera = 1; ?>
<br>
<td style="width: 131px"></td>
<input name="guardar" type="submit" value="Guardar" />
</form>
<table width="200" border="0">
<tr>
<td><?php echo $_POST['COD_CLI'];?></td>
</tr>
<tr>
<td><?php echo $_POST['PRECIO']; ?></td>
</tr>
<tr>
<td><?php echo $_POST['CANTIDAD']; ?></td>
</tr>
<tr>
<td><?php echo $_POST['SUBTOTAL']; ?></td>
</tr>
<tr>
<td><?php echo $_POST['TOTAL']; ?></td>
</tr>
<tr>
<td><?php echo $fecha; ?></td>
</tr>
<tr>
<td><?php echo $_POST['ID_PROD']; ?></td>
</tr>
<tr>
<td><?php echo $n_ped; ?></td>
</tr>
</table>
</body>
</html>
<?php }?>

ya controle los nombres y si las variables tienen datos y todo esta en forma. verifique el formato de la fecha y sta bien. no se. ojala me puedan ayudar. gracias.