Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/03/2013, 08:18
Alber_h
 
Fecha de Ingreso: septiembre-2009
Mensajes: 138
Antigüedad: 15 años, 5 meses
Puntos: 3
Codigo php select

Tengo los siguientes codigos en php,ajax,html respectivamente para poder insertar un registro en mi base de datos;al momento de realizar todas las consultas el campo producto y descripcion me sale vacio pero el campo total me sale con registro.


Php:
<?php

$con=mysql_connect("localhost","root","");
$sbd=mysql_select_db("bdventas");


$producto=$_POST['producto'];
$descripcion=$_POST['descripcion'];
$total=$_POST['total'];

$ins="insert into ventas (producto,descripcion,total) values('".$producto."','".$descripcion."','".$tota l."')";

$ejec=mysql_query($ins);


?>


Ajax:
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function Insertarventas(){
//donde se mostrará lo resultados
var pro,des,tot;
//valores de los inputs
pro=document.form.producto.value;
des=document.form.descripcion.value;
tot=document.form.total.value;

//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medoto POST
//archivo que realizará la operacion
//registro.php
ajax.open("POST", "inserventas.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divResultado.innerHTML = ajax.responseText
//llamar a funcion para limpiar los inputs
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//enviando los valores
ajax.send("producto="+pro+"&descripcion="+des+"&to tal="+tot)
}



html:
<form name="form" method="post" onSubmit="Insertarventas(); return false">
<div id="Layer44">
<br>
<br>
<table style="border:1px solid #FF0000; color:#000099;width:400px;" align="center">
<tr style="background:#99CCCC;">
<td align="center">Producto</td>
<td align="center">Descripcion</td>
<td align="center">Precio</td>
<td align="center">Cantidad</td>
<td align="center">Accion</td>
<td align="center">Total</td>
</tr>

<tr id="princ">

<td align="center">

<select id="producto">

<option>-------------------</option>

<option id="op1">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select nombre from producto where id_producto=1";

$sqlnn=mysql_query($sqln);
while($producto=mysql_fetch_array($sqlnn))
{
echo $producto['nombre'];
}
?>

</option>

<option id="op2">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select nombre from producto where id_producto=2";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['nombre'];
}
?>

</option>

<option id="op3">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select nombre from producto where id_producto=3";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['nombre'];
}
?>

</option>

<option id="op4">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select nombre from producto where id_producto=4";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['nombre'];
}
?>

</option>

<option id="op5">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select nombre from producto where id_producto=5";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['nombre'];
}
?>

</option>


</select>

</td>
<td align="center">

<select id="descripcion">

<option>-------------------</option>

<option id="d1">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select descripcion from producto where id_producto=1";

$sqlnn=mysql_query($sqln);
while($descripcion=mysql_fetch_array($sqlnn))
{
echo $descripcion['descripcion'];
}
?>

</option>

<option id="d2">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select descripcion from producto where id_producto=2";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['descripcion'];
}
?>

</option>


<option id="d3">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select descripcion from producto where id_producto=3";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['descripcion'];
}
?>

</option>


<option id="d4">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select descripcion from producto where id_producto=4";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['descripcion'];
}
?>

</option>



<option id="d5">

<?php $conn =mysql_connect("localhost","root","");

$seln =mysql_select_db("bdventas");

$sqln ="select descripcion from producto where id_producto=5";

$sqlnn=mysql_query($sqln);
while($fila=mysql_fetch_array($sqlnn))
{
echo $fila['descripcion'];
}
?>

</option>

</select>


</td>

<td align="center"><input type="text" id="precio"></input></td>
<td align="center"><input type="text" id="cantidad"></input></td>
<td align="center"><input type="button" value="calcular" onClick="calcular()"></input></td>
<td align="center"><input type="text" name="total" id="total"></input></td>

</tr>

</table>
</div>
<div id="Layer45">
<div align="center">
<table>

<tr>
<td><input type="submit" name="Submit4" value="Agregar"></td>
</tr>



</table>
<br>
<table>
<tr>
<td><input type="submit" name="Submit4" value="Guardar" onClick="alertaff()"></td>
</tr>
</table>

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