PHP - Error conexion con BBDD

 
Vista:
sin imagen de perfil
Val: 9
Ha aumentado su posición en 14 puestos en PHP (en relación al último mes)
Gráfica de PHP

Error conexion con BBDD

Publicado por php (13 intervenciones) el 30/04/2021 18:17:59
Tengo un problema a la hora de que me muestre el resultado de una consulta SQL que se hace en este archivo.
Se muestra solo un formulario con el desplegable para tipología, pero solo muestra la opción "TODOS", es decir no llega a conectar a BBDD.

Os pongo primero el ejemplo que no funciona, luego otro ejemplo en el que funciona hacer una consulta y finalmente el archivo entero.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<tr>
     <td class="titulo">Tipolog&iacute;a:<br />
    <select name="btipo" id="btipo" style="width:140px;">
      <option value="0"> - Todos - </option>
 
         <?php
      $sql="SELECT * FROM t_producto2_cat PC, t_producto2_cat_texto PCT WHERE PC.pk_producto2_cat=PCT.fk_producto2_cat AND PCT.fk_idioma=1 AND PC.pro_cat_activo ORDER BY PC.pro_cat_orden";
      $res=mysqli_query($sql);
      while($reg=mysqli_fetch_array($res)){
      ?>
      <option value="<?=$reg["pk_producto2_cat"];?>"><?=$reg["pro_cat_nombre"];?></option>
      <?php
      }?>
    </select>
     </td>
</tr>

En cambio esta consulta si que muestra los banners
1
2
3
4
5
6
7
8
9
<?php
    $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
    $obj->conectar();
    $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.ban_orden=3 AND B.ban_activo=1 ORDER BY B.ban_orden");
    $num_reg=$obj->obtenNumRegs();
    if($num_reg>0){
        $reg=$obj->obtendatos();
    }
?>

En el segundo ejemplo que si que funciona veo que hace:
1
2
$obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
$obj->conectar();

Pero he probado a hacerlo en el trozo del codigo que no me funciona y sigue sin mostrar resultados.

Os dejo tambien el archivo entero. (index.php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
include("./libreria/class.carrito.php");
session_start();
include("./libreria/class.mysql.php");
include("./libreria/conn.php");
include("./libreria/funciones.php");
include('./libreria/inicia_sesion_carrito.php');
 
echo "Nombre de usuario: " . $_SESSION["usuario"];
 
$obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
 
$obj->conectar();
$obj->consultar($sql);
$reg=$obj->obtendatos();
 
 
if(!isset($_SESSION["sMostrarPrecios"])){
	$_SESSION["sMostrarPrecios"]=1;
}
 
if(isset($_GET["precios"])){
	if($_GET["precios"]=="1"){
		$_SESSION["sMostrarPrecios"]=1;
	}elseif($_GET["precios"]==="0"){
		$_SESSION["sMostrarPrecios"]=0;
	}
	header("Location: index.php");
	exit;
}
 
if(isset($_POST['service']) && $_POST['service'] <> ''){
	if(isset($_POST["tipoNeumatico"]) && $_POST["tipoNeumatico"]>0){
		$where=" AND fk_producto2_cat='".$_POST["tipoNeumatico"]."'";
	}
	$sql="SELECT DISTINCT(P.pro_descripcion_buscador) FROM t_producto2 P, t_producto2_texto PT WHERE P.pk_producto2=PT.fk_producto2 AND PT.fk_idioma=1 AND P.pro_activo AND P.pro_descripcion_buscador LIKE '".$_POST['service']."%' ".$where." ORDER BY P.pro_descripcion_buscador LIMIT 0,10";
	$res=mysqli_query($sql);
	while($reg=mysqli_fetch_array($res)){
		echo '<div class="suggest-element"><a data="'.$reg["pro_descripcion_buscador"].'" id="service'.$reg['pk_producto2'].'">'.$reg["pro_descripcion_buscador"].'</a></div>';
	}
	exit;
}
 
if($_GET[cerrar]=="ok"){
	$_SESSION[usuario]="";
}
 
/*if($_SESSION[usuario]<>""){
	header("Location: ./acceso_cliente.php");
	exit;
}*/
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel=�icon� type=�image/png� href=�images/favicon.png�/>
<title>Neumaticos Recambios Segorbe</title>
<script type='text/javascript' src='./libreria/jquery-autocomplete.js'></script>
<script type="text/javascript" src="./libreria/run.js"></script>
<script>
function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}
function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}
function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function cargarcookie(info){
	// Cu�ntas veces
	var usuario = getCookie('usuario')
	if ( usuario!= null) {
		document.form1.user.value=usuario;
	}
 
}
 
</script>
<script type="text/javascript">
$(document).ready(function() {
	//Al escribr dentro del input con id="service"
	$('#breferencia').keyup(function(){
		var tipoNeumatico = $('#btipo').val();
		//Obtenemos el value del input
		var service = $(this).val();
		var dataString = 'service='+service+'&tipoNeumatico='+tipoNeumatico;
 
 
		if(service=='' || service==null){
			$('#suggestions').fadeOut(1);
		}else{
			//Le pasamos el valor del input al ajax
			$.ajax({
				type: "POST",
				url: "index.php",
				data: dataString,
				success: function(data) {
					//Escribimos las sugerencias que nos manda la consulta
					$('#suggestions').fadeIn(1000).html(data);
					//Al hacer click en algua de las sugerencias
					$('.suggest-element a').live('click', function(){
						//Obtenemos la id unica de la sugerencia pulsada
						var id = $(this).attr('id');
						//Editamos el valor del input con data de la sugerencia pulsada
						$('#breferencia').val($('#'+id).attr('data'));
						//Hacemos desaparecer el resto de sugerencias
						$('#suggestions').fadeOut(1000);
 
						//alert('Has seleccionado el '+id+' '+$('#'+id).attr('data'));
						return false;
					});
				}
			});
		}
    });
});
 
</script>
<style>
.suggest-element{
padding-left:5px;
padding-top:5px;
padding-bottom:5px;
width:120px;
cursor:pointer;
border-bottom:1px solid #000;
}
.suggest-element a, .suggest-element a:hover{
	font-family:Verdana, Geneva, sans-serif;
	font-size:11px;
	color:#000;
	font-weight:normal;
	display:inline;
	width:100%;
}
#suggestions {
width:150px;
height:80px;
overflow: auto;
background-color:#FFF;
display:none;
}
</style>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link href="estilos.css" rel="stylesheet" type="text/css">
<link href="styleshop.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.Estilo1 {color: #FFB442}
-->
</style>
<?php include("includes/cookies.php");?>
</head>
 
<?php
$img_cabecera="cabecera-index.jpg";
include("includes/cabecera.php"); ?>
            <table width="754"  border="0" cellspacing="0" cellpadding="0" >
              <tr>
                <td align="center" valign="top">
                  <table width="100%" height="40"  border="0" cellpadding="0" cellspacing="0">
                    <?php
                    if($_SESSION["usuario"]<>""){
						if(permiteBusquedasConsultas()){
					?>
                  <tr>
                    <td width="608" height="238" colspan="3" valign="top" class="backBuscadorNew">
                    <table width="100%" border="0">
                      <tr>
                        <td width="178" valign="top" class="buscaMini">
                        <form name="formBusca01" method="get" action="listado.php">
                         <table width="95%" border="0">
                           <tr>
                             <td class="titulo">Tipolog&iacute;a:<br />
                            <select name="btipo" id="btipo" style="width:140px;">
                              <option value="0"> - Todos - </option>
 
								 <?php
                              $sql="SELECT * FROM t_producto2_cat PC, t_producto2_cat_texto PCT WHERE PC.pk_producto2_cat=PCT.fk_producto2_cat AND PCT.fk_idioma=1 AND PC.pro_cat_activo ORDER BY PC.pro_cat_orden";
                              $res=mysqli_query($sql);
                              while($reg=mysqli_fetch_array($res)){
                              ?>
                              <option value="<?=$reg["pk_producto2_cat"];?>"><?=$reg["pro_cat_nombre"];?></option>
                              <?php
                              }?>
                            </select>
                             </td>
                           </tr>
 
                           <tr>
                             <td class="titulo">Referencia<br>
                                <input name="breferencia" id="breferencia" style="width:140px;" class="campo" type="text" autocomplete="off" /><br>
                                <div class="txtMini">Ejemplo: 1557013</div><div id="suggestions"></div>
                             </td>
                           </tr>
                           <tr>
                             <td><input name="buscar" type="submit" class="boton" value="Buscar" style="background-color:#000;" /></td>
                           </tr>
                         </table>
                        </td>
                        <td>&nbsp;</td>
                        <td width="210" valign="top" class="buscaMini"><?php include("includes/buscador.php");?></td>
                      </tr>
                    </table>
                    </form>
                    </td>
                  </tr>
                    <?php
						}
					}else{
					?>
                  <tr>
                    <td width="608" height="153" colspan="3" valign="top">
					  <?php
            if(isMobile()){?>
            <img src="./uploads/fotoflash.jpg" />
            <?php
            }else{
                        $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
                        $obj->conectar();
                        $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.pk_banner=0 AND B.ban_activo=1 ORDER BY B.ban_orden");
                        $num_reg=$obj->obtenNumRegs();
                        if($num_reg>0){
                            $reg=$obj->obtendatos();
                      ?>
 
            <img src="./uploads/banner/<?=$reg->ban_imagen;?>" width="750" height="372" >
                        </td>
                    </tr>
      						<?php }
            }?>
                    <?php }?>
                    <tr>
                    <td>
                    <table width="754"  border="0" cellspacing="0" cellpadding="0" style="float:left; margin-top:10px;">
                    <tr>
					  <?php
                        $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
                        $obj->conectar();
                        $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.ban_orden=2 AND B.ban_activo=1 ORDER BY B.ban_orden");
            						$num_reg=$obj->obtenNumRegs();
            						if($num_reg>0){
            	                        $reg=$obj->obtendatos();
            						}
                        if($_SESSION["sMostrarPrecios"]==1){
                          $enlace="./uploads/banner/1_img_presupuesto.jpg";
                          $url="./index.php?precios=0";
                          $titulo="Acceder a Presupuestos";
                        }else{
                          $enlace="./uploads/banner/1_img_pedido.jpg";
                          $url="./index.php?precios=1";
                          $titulo="Acceder a Pedidos";
                        }
                      ?>
                    <td width="290px" height="120" rowspan="2"><a href="<?=$url;?>"><img src="<?=$enlace;?>" width="290" border="0" alt="<?=$titulo?>" title="<?=$titulo?>" /></a></td>
                    <!--<td width="290px" height="120" rowspan="2"><?php if($num_reg>0){?><?php if($reg->ban_enlace<>""){?><a href="<?=$reg->ban_enlace;?>"<?php if($reg->ban_target==1){?> target="_blank"<?php }?>><?php }?><img src="./uploads/banner/<?=$reg->ban_imagen;?>" width="290" border="0" alt="<?=$reg->ban_titulo?>" title="<?=$reg->ban_titulo?>" /><?php if($reg->ban_enlace<>""){?></a><?php }?><?php }?></td>-->
					  <?php
                        $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
                        $obj->conectar();
                        $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.ban_orden=3 AND B.ban_activo=1 ORDER BY B.ban_orden");
						$num_reg=$obj->obtenNumRegs();
						if($num_reg>0){
	                        $reg=$obj->obtendatos();
						}
                      ?>
                    <td rowspan="2"><?php if($num_reg>0){?><?php if($reg->ban_enlace<>""){?><a href="<?=$reg->ban_enlace;?>"<?php if($reg->ban_target==1){?> target="_blank"<?php }?>><?php }?><img src="./uploads/banner/<?=$reg->ban_imagen;?>" width="290" border="0" alt="<?=$reg->ban_titulo?>" title="<?=$reg->ban_titulo?>" /><?php if($reg->ban_enlace<>""){?></a><?php }?><?php }?></td>
                    </tr>
                    <tr>
 
                    </tr>
                      <tr>
                    <td height="14"></td>
                    <td></td>
                    </tr>
                      <tr>
					  <?php
                        $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
                        $obj->conectar();
                        $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.ban_orden=4 AND B.ban_activo=1 ORDER BY B.ban_orden");
						$num_reg=$obj->obtenNumRegs();
						if($num_reg>0){
	                        $reg=$obj->obtendatos();
						}
                      ?>
                        <td height="60"><?php if($num_reg>0){?><?php if($reg->ban_enlace<>""){?><a href="<?=$reg->ban_enlace;?>"<?php if($reg->ban_target==1){?> target="_blank"<?php }?>><?php }?><img src="./uploads/banner/<?=$reg->ban_imagen;?>" width="290" border="0" alt="<?=$reg->ban_titulo?>" title="<?=$reg->ban_titulo?>" /><?php if($reg->ban_enlace<>""){?></a><?php }?><?php }?></td>
					  <?php
                        $obj=new conectarBBDD(SERVER,USER,PASS,BBDD);
                        $obj->conectar();
                        $obj->consultar("select * from t_banner B, t_banner_texto BC WHERE B.pk_banner=BC.fk_banner && BC.fk_idioma=1 && B.ban_orden=5 AND B.ban_activo=1 ORDER BY B.ban_orden");
						$num_reg=$obj->obtenNumRegs();
						if($num_reg>0){
	                        $reg=$obj->obtendatos();
						}
                      ?>
                        <td><?php if($num_reg>0){?><?php if($reg->ban_enlace<>""){?><a href="<?=$reg->ban_enlace;?>"<?php if($reg->ban_target==1){?> target="_blank"<?php }?>><?php }?><img src="./uploads/banner/<?=$reg->ban_imagen;?>" width="290" border="0" alt="<?=$reg->ban_titulo?>" title="<?=$reg->ban_titulo?>" /><?php if($reg->ban_enlace<>""){?></a><?php }?><?php }?></td>
                      </tr>
                    </table>
                    </td>
                    </tr>
 
                </table></td>
              </tr>
            </table>
            <table width="756" height="52"  border="0" cellpadding="0" cellspacing="0" style="float:left; margin-top:20px">
              <tr>
                <td width="756" height="52" background="images/sinal_clientes.jpg"><table width="100%"  border="0" cellpadding="0" cellspacing="0" class="textobajo">
                  <tr>
                    <td width="3%">&nbsp;</td>
                    <td width="93%" align="center" style="color:#FFF">Calle de la Molineta, 2 Canet de Berenguer (Valencia) Tel.96 269 83 24 Fax.96 267 21 75 </td>
                    <td width="4%">&nbsp;</td>
                  </tr>
                </table></td>
              </tr>
            </table></html>
        </tr>
      </table>
<?php include("includes/columnaderecha.php"); ?>
<?php include("includes/pie.php"); ?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder