Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/08/2012, 01:05
neveuster
 
Fecha de Ingreso: febrero-2012
Mensajes: 163
Antigüedad: 12 años, 2 meses
Puntos: 0
Error al insertar un ejecutar busqueda

Hola, estoy intentando hacer una busqueda en un php que se llama venta, el procedimiento se hace en otro php y luego devuelve el resultado pero el error que me aparece es:
Cita:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\prueba\3\buscaproducto.php on line 10
Luego le puse comillas simples a : la consulta from productos where codigo=$d";

pero ahora se pasa de largo y me aparece el mensaje del else osea... codigo de producto incorrecto.

he revisado varias veces pero no doy con el error... la base de datos contiene registros para probar y no logro resolverlo... ven algún error en estos codigos? falta algo? sobra algo? les pido de su ayuda... desde ya gracias!!.


Código PHP:
<?php

$c
=mysql_connect("localhost","root","1234");
mysql_select_db("ventas");
$d=0;
$consulta="select max(folio) from ventas";
$r=mysql_query($consulta);

$dato=mysql_fetch_row($r);
$d=$dato[0]+1;

mysql_close();
?>




<html>
<head>
    <title> venta </title>
<script type="text/javascript">

    function grabar(){

        var d1=document.getElementById("folio");
        var d2=document.getElementById("fecha");
        var d3=document.getElementById("clave");

        var ad1=d1.value;
        var ad2=d2.value;
        var ad3=d3.value;
                
        var t=document.getElementById("listado");        

        var envio="folio="+ad1+"&fecha="+ad2+"&clave="+ad3;
        var valor="";
        var a1="";
        var a2="";
        var a3="";
        
        for (var linea=1;linea<t.rows.length;linea++){
            
            a1=t.rows[linea].cells[0].innerHTML;
            a2=t.rows[linea].cells[1].innerHTML;
            a3=t.rows[linea].cells[4].innerHTML;
            
            valor="&w"+linea+"="+a1+"&x"+linea+"="+a2+"&y"+linea+"="+a3;
            envio=envio+valor;
            }
    
        try{ var ajax= new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e){
            try{ var ajax=new ActiveXObject("MicrosoftXMLHTTP"); }
        catch(E){ var ajax=false; }
        }

        if (!ajax && typeof XMLHttpRequest!='undefined'){
            var ajax=new XMLHttpRequest();
        }

        ajax.onreadystatechange=function(){
        var zona=document.getElementById("mensaje");
        if (ajax.readyState==4){
           if (ajax.status==200){
            zona.innerHTML=ajax.responseText;
            }}
        }
        
        

        ajax.open("POST","vendido.php",true);
        ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajax.send(envio);

           }





    function buscac(){
        var dato=document.getElementById("clave");
        var d=dato.value;

        try{ var ajax= new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e){
            try{ var ajax=new ActiveXObject("MicrosoftXMLHTTP"); }
        catch(E){ var ajax=false; }
        }

        if (!ajax && typeof XMLHttpRequest!='undefined'){
            var ajax=new XMLHttpRequest();
        }

        ajax.onreadystatechange=function(){
        var zona=document.getElementById("cliente");
        if (ajax.readyState==4){
           if (ajax.status==200){
            zona.innerHTML=ajax.responseText;
            }}
        }

        ajax.open("POST","buscacliente.php",true);
        ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajax.send("clave="+d);

           }

    function articulo(){
        var dato=document.getElementById("codigo");
        var d=dato.value;

        try{ var ajax= new ActiveXObject("Msxml2.XMLHTTP"); }
        catch(e){
            try{ var ajax=new ActiveXObject("MicrosoftXMLHTTP"); }
        catch(E){ var ajax=false; }
        }

        if (!ajax && typeof XMLHttpRequest!='undefined'){
            var ajax=new XMLHttpRequest();
        }

        ajax.onreadystatechange=function(){
        var zona=document.getElementById("datapro");
        if (ajax.readyState==4){
           if (ajax.status==200){
            zona.innerHTML=ajax.responseText;
            }}
        }

        ajax.open("POST","buscaproducto.php",true);
        ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        ajax.send("codigo="+d);

           }

    

    function actual(){
    var n=new Date();
    var f=document.getElementById("fecha");
    f.value=n.getFullYear()+"-"+n.getMonth()+"-"+n.getDay();
        
    }

function listado(){
    var c=document.getElementById("codigo");
    var can=document.getElementById("cantidad");
    var des=document.getElementById("descripcion");
    var tam=document.getElementById("tamano");
    var exi=document.getElementById("existencia");
    var pre=document.getElementById("precio");
    
    var x=parseInt(can.value,10);
    var y=parseInt(exi.value,10);
    if (x > y){
        alert ("Existencia del producto insuficiente");
        }
    else{
        var st=x*parseInt(pre.value);
    
        var t=document.getElementById("listado");
        var l=t.rows.length;
        t.insertRow(l);
        
        var c1=document.createElement("td");
        c1.innerHTML=c.value;
        
        var c2=document.createElement("td");
        c2.innerHTML=can.value;

        var c3=document.createElement("td");
        c3.innerHTML=des.value;

        var c4=document.createElement("td");
        c4.innerHTML=tam.value;

        var c5=document.createElement("td");
        c5.innerHTML=pre.value;

        var c6=document.createElement("td");
        c6.innerHTML=st
        
        t.rows[l].appendChild(c1);
        t.rows[l].appendChild(c2);
        t.rows[l].appendChild(c3);
        t.rows[l].appendChild(c4);
        t.rows[l].appendChild(c5);
        t.rows[l].appendChild(c6);

        var p=document.getElementById("pago");
        var dinero=parseInt(p.value);
        p.value=dinero+st
        
        
        }
    }

</script>
<style type="text/css">
#cliente {
    position:absolute;
    left:363px;
    top:21px;
    width:451px;
    height:115px;
    z-index:1;
}
#datapro {
    position:absolute;
    left:206px;
    top:180px;
    width:611px;
    height:72px;
    z-index:2;
}
#ppp {
    position:absolute;
    left:501px;
    top:262px;
    width:300px;
    height:31px;
    z-index:3;
}
#mensaje {
    position:absolute;
    left:300px;
    top:400px;
    width:300px;
    height:50px;
    z-index:4;
}

</style>
</head>
<body onLoad="actual();">

<div id="ppp">Total:
  <input type="text" name="pago" id="pago" value="0"> 
</div>
<form name="venta">
<p>Num de Folio<?php echo ("<input type=\"text\" name=\"folio\" id=\"folio\" value=\"$d\" DISABLED>"); ?></p>

<p>Fecha <input type="text" name="fecha" id="fecha"></p>
<p>clave del cliente
  <input type="number" id="clave" REQUIERED><input type="button" value="buscar" onClick="buscac();">
</p>
<p>&nbsp;</p>
    <p>Codigo
  </p>
  <p>
  <input name="codigo" type="text" id="codigo" REQUIERED>
      <input type="button" name="bb" id="bb" value="&gt;&gt;" onClick="articulo();" >
      
    </p>
  <p>
    <input type="button" name="agrega" id="agrega" value="+" onClick="listado();"> <input type="button" value="Cobrar" onClick="grabar();">
  </p>
  <table id="listado" width="100%" border="1">
    <tr>
    <td>Codigo</td>
    <td>Cantidad</td>
    <td>Descripcion</td>
    <td>Tamaño</td>
    <td>Precio U.</td>
    <td>Precio T.</td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp; </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="cliente">
  
</div>
<div id="datapro">

</div>
<div id="mensaje">

</div>

</form>
</body>
</html>



Código PHP:
<?php
$d
=$HTTP_POST_VARS['codigo'];

$c=mysql_connect("localhost","root","1234");
mysql_select_db("ventas");

$consulta="select descripcion,tamano,existencia,precio from productos where codigo='$d'";
$r=mysql_query($consulta);

$l=mysql_num_rows($r);
if (
$l>0){
$dato=mysql_fetch_row($r);
echo(
"<h6 align=\"center\">CodigoOOOOOOOOOOOOOOOOOOOO <h6> ");
echo (
"<table><tr><td>Cantidad</td><td>Descripcion</td><td>Tamano</td><td>Existencia</td><td>Precio</td></tr>");
echo (
"<tr><td><input type=\"number\" name=\"cantidad\" id=\"cantidad\" min=1 size=3 value=\"1\"></td>");
echo (
"<td><input type=\"text\" name=\"descripcion\" id=\"descripcion\" value=\"$dato[0]\" DISABLED></td>");
echo (
"<td><input type=\"text\" name=\"tamano\" id=\"tamano\" value=\"$dato[1]\" DISABLED></td>");
echo (
"<td><input type=\"text\" name=\"existencia\" id=\"existencia\" value=\"$dato[2]\" DISABLED></td>");
echo (
"<td><input type=\"text\" name=\"precio\" id=\"precio\" value=\"$dato[3]\" DISABLED></td></tr></table>");

}
else{
echo(
"<h6 align=\"center\">Codigo de producto incorrecto <h6> ");

}

mysql_close();
?>

Gracias por la ayuda...