Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/02/2011, 11:30
cristaken
 
Fecha de Ingreso: septiembre-2010
Mensajes: 75
Antigüedad: 13 años, 7 meses
Puntos: 1
Problema mysql_fetch_array

Hola a todos!

quería pedirles un favor, es q tengo un problemita el cual no se como resolverlo, pues veo que tengo el script bn, pero me sale el siguiente error:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Pagina\ff11sjdd\Admin\x1nuser2\def ault.php on line 211

Y no entiendo porque si el script esta bn y lo revise como muchas veces, el script es:
Código:

if (isset($_REQUEST['nhardware'])) {

    $nombre_hardware = $_POST['nombre_hardware'];
    $firmware = $_POST['firmware'];

    $conexion = new Conexion();
    $conexion->conectar();
    //Se consulta si ya existe el firmware
    $resultado = $conexion->consulta("SELECT count( * ) FROM hardware WHERE nombre_hardware = '" . $nombre_hardware . "'");
    while ($res = mysql_fetch_array($resultado)) {
        $x = $res['count( * )'];
    }


    //se consulta el id para el firmware nuevo
    $resultado = $conexion->consulta("SELECT idhardware from hardware");
    $i = 0;
    while ($res = mysql_fetch_array($resultado)) {
        $id[$i] = $res['idhardware'];
        $i++;
    }
    sort($id);
    $idf = ($id[$i - 1]) + 1; // Se establece el id del firmware nuevo
    //Si el firmware no existe se crea, si existe no entra a insertar nada

    if ($x == "0") {
        $resultado = $conexion->consulta("INSERT INTO hardware(idhardware,nombre_hardware) VALUES('" . $idf . "','" . $nombre_hardware . "')");
    }

    $resultado = $conexion->consulta("select idhardware from hardware where nombre_hardware='" . $nombre_hardware . "'");
    $res = mysql_fetch_array($resultado);
    $idf = $res['idhardware'];

    $msjf = true;
    for ($i = 0; $i < count($firmware); $i++) {
        $j = 0;
        $resultado = $conexion->consulta('SELECT idproductos from firmwarexproducto where idfirmware = '. $firmware[$i] .' ');
        while ($res = mysql_fetch_array($resultado)) { // Esta es la linea 211!

            $idp[$j] = $res['idproductos'];
            
            if (!empty($idp)) {
                $resultado = $conexion->consulta("INSERT INTO hardwarexproducto (idproducto,idhardware) VALUES(" . $idp[$j] . ", '" . $idf . "')");
            } else {
                $msjf = false;
            }            
            $j++;            
        }
    }

    if ($msjf == true) {
        echo "Se ha guardado su nuevo hardware";
        return false;
    } else {
        echo "Uno o más hardware x Producto ya existen, estos se han saltado y se ha seguido con la insercion de los demas hardware";
        return false;
    }
}
y la clase conexion.php es:

Código:
<?php
class Conexion {

    private $conexion;
    private $resultados;
    private $error;

    function conectar() {
        $this->conexion = mysql_connect("localhost", "root", "") or die("Problemas en la conexion");
        mysql_select_db("mydb", $this->conexion) or die("Problemas en la selección de la base de datos");
    }

    function consulta($consulta) {        
        $resultados = mysql_query($consulta, $this->conexion) or die("Problemas en la consulta: " . mysql_error());
        $this->error = mysql_errno();
        return $resultados;
    }

    function cerraConexion() {
        mysql_close($this->conexion);
    }

    function devuelveError() {
        return $this->error;
    }

}

?>
realmente les agradecería mucho la ayuda de ustedes :D