PHP - obtener el valor del referido

 
Vista:

obtener el valor del referido

Publicado por David (1 intervención) el 12/04/2019 18:00:47
Buenas a todos quisiera ver si alguien me puede ayudar estoy creando un formulario en el cual tengo un campo de referido en el cual ingreso una cedula y quiero que al rato que le ingreso que me de el nombre de la persona que le pertenece esa cedula o si no que me diga que no existe a qui les dejo el codigo el campo es $refe

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
<?php
 
	$cedula 	= 	$_SESSION['cedula_usuario'];
 
	//$puerto = $_GET["puerto"];
 
	$cedula_emp = $_GET["cedula"];
 
	$cliente = "SELECT
				dbo.clientes.razon_social, 
				dbo.dimEstado.nombreEstado, 
				dbo.clientes.direccion, 
				dbo.clientes.telefonos,
				dbo.clientes.email,
				dbo.clientes.id_referidor,
				dbo.clientes.nit
			FROM
				dbo.clientes INNER JOIN
				dbo.dimciudad ON dbo.clientes.CODCIUDAD = dbo.dimciudad.codciudad INNER JOIN
				dbo.dimEstado ON dbo.dimciudad.codestado = dbo.dimEstado.codEstado
			WHERE
				dbo.clientes.nit = '".$cedula_emp."'";
 
	$consulta_cliente = mssql_query($cliente);
	$existe = mssql_num_rows($consulta_cliente);
 
	for($i=0;$fila=mssql_fetch_row($consulta_cliente);$i++){
		$nombre = utf8_encode($fila[0]);
		$provincia = $fila[1];
		$direccion = $fila[2];
		$telefono = $fila[3];
		$correo = $fila[4];
		$refe = $fila[5];
 
	}
 
	$provincias = mssql_query("SELECT codestado,nombreestado FROM dimEstado WHERE codpais = 593 ORDER BY nombreestado");
 
?>
 
<html>
 
<head>
 
	<script>
 
		$(document).ready(function() {
 
 
		// carga de datos de los estados y sus respectivas ciudades
		$('#cbo_canton').attr('disabled','-1');
 
			$("#cbo_provincia").change(function(){
 
			    $('#cbo_canton').removeAttr('disabled');
 
				var $valor_estado  = $("#cbo_provincia").val()
				if ($valor_estado==0 || $valor_estado==-1) {
 
					$("#cbo_canton").html('');
					$("#cbo_canton").html('<option value="0">SELECCIONE ...</option>\n');
 
					//desactiva cbos
					$('#cbo_canton').attr('disabled','-1');
 
				}else{
 
					$.ajax({
					type: "POST",
					dataType:"html",
					url: "datos/busca_estados_x_ciudad.php",
					data: "id_estado="+$("#cbo_provincia").val(),
					beforeSend: function() {
						setTimeout ('', 1500);
						$("#cbo_canton").html('');
					},
 
					cache: false,
					success: function(result) {
 
						//alert(result)
						$('#cbo_canton').append(result);
						return result;
 
					},
					error: function(error) {
						alert("Problemas con la Carga de la Data para las Ciudades: " + error);
					}
 
					});
 
				} //--- fin del else
 
 
			});	//----fin carga de datos de los estados y sus respectivas ciudades
		});
 
 
		function guardar(){
			var regex = /[\w-\.]{2,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
 
			if (!regex.test($('#email').val().trim())) {
				var mes = 'Info|El correo ingresado no es valido...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
 
			}
 
 
			if($('#txt_apellido').val()==''){
				var mes = 'Info|Debe ingresar el apellido...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
			}
 
			if($('#cbo_provincia').val() == -1){
				var mes = 'Info|Debe seleccionar la provincia...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
			}
 
			if($('#cbo_canton').val()==''){
				var mes = 'Info|Debe seleccionar el canton...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
			}
 
			if($('#txt_direccion').val()==''){
				var mes = 'Info|Debe ingresar una direccion...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
			}
 
			var telefono;
			if($('#txt_telefono').val()==''){
				var mes = 'Info|Debe ingresar un numero de celular valido...';
				$.Notify({
					caption: mes.split("|")[0],
					content: mes.split("|")[1],
					type: 'alert'
				});
				return;
			}
			var refe;
			if($('#txr_refe').val()==''){
			var mes = 'Info|Debe ingresar un numero valido';
			$.Notify({
				caption: mes.split("|")[0],
				content: mes.split("|")[1],
				type:'alert'
				});
				return;
			}
 
			var num_cedula = '<?php echo $cedula_emp;?>';
 
			$.ajax({
				type: "POST",
				dataType:"html",
				url: "datos/guarda_formulario_web.php",
				data: "nombre="+$('#txt_nombre').val()+
						"&apellido="+$('#txt_apellido').val()+
						"&direccion="+$('#txt_direccion').val()+
						"&telefono="+$('#txt_telefono').val()+
						"&email="+$('#email').val()+
						"&refe="+$('#txt_refe').val()+
						"&provincia="+$('#cbo_provincia').val()+
						"&canton="+$('#cbo_canton').val()+
						"&cedula="+num_cedula,
				cache: false,
				success: function(result) {
					alert(result);
					resultado=result.split("/");
					if(resultado[1] == 1){
						var mes = 'Info|'+resultado[0];
						$.Notify({
							caption: mes.split("|")[0],
							content: mes.split("|")[1],
							type: 'success'
						});
 
						setTimeout(function(){document.location.reload(true)}, 9500);
					}
					else{
							var mes = 'Info|'+resultado[0];
							$.Notify({
								caption: mes.split("|")[0],
								content: mes.split("|")[1],
								type: 'alert'
							});
					}
 
 
				},
				error: function(error) {
					alert("	jquery - Algunos problemas han ocurrido. Por favor, inténtelo de nuevo más tarde: " + error);
				}
 
			});
 
		}
 
	</script>
 
</head>
 
<body>
 
	<?php if($existe>0){ ?>
 
	<h2 class="bg-red fg-white" align="center">
		YA SE ENCUENTRA REGISTRADO(A)
	</h2>
 
	<table class="table bordered" border="1">
		<tr class="bg-cyan fg-white">
			<th><label class="text-accent">Nombre</label></th>
			<th><label class="text-accent">Provincia</label></th>
			<th><label class="text-accent">Direccion</label></th>
			<th><label class="text-accent">Celular</label></th>
			<th><label class="text-accent">Correo</label></th>
			<th><label class="text-accent">Persona</label></th>
		</tr>
		<tr>
			<td><?php echo trim($nombre);?></td>
			<td><?php echo trim($provincia);?></td>
			<td><?php echo trim($direccion);?></td>
			<td><?php echo trim($telefono);?></td>
			<td><?php echo trim($correo);?></td>
			<td><?php echo trim($refe);?></td>
		</tr>
	</table>
 
	<?php }else{ ?>
 
	<table class="table bordered hovered striped" border="1">
		<tr class="text-accent bg-grayLight">
			<th colspan="2">INGRESE SUS DATOS DE REGISTRO</th>
		</tr>
		<tr>
			<th><label class="text-accent">Nombre:</label></th>
			<td>
				<div class="input-control text">
					<input type="text" name="txt_nombre" id="txt_nombre" placeholder="Nombre" onkeyup="mayus(this);">
				</div>
				<div class="input-control text">
					<input type="text" name="txt_apellido" id="txt_apellido" placeholder="Apellido" onkeyup="mayus(this);">
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Provincia:</label></th>
			<td>
				<div class="input-control select">
					<select name="cbo_provincia" id="cbo_provincia">
						<option value="-1">SELECCIONE...</option>
						<?php for($i=0;$fila=mssql_fetch_row($provincias);$i++){ ?>
						<option value="<?php echo $fila[0];?>"><?php echo trim(utf8_encode($fila[1]));?></option>
						<?php } ?>
					</select>
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Cant&oacute;n:</label></th>
			<td>
				<div class="input-control select">
					<select name="cbo_canton" id="cbo_canton">
					</select>
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Direccion:</label></th>
			<td>
				<div class="input-control text">
					<input type="text" name="txt_direccion" id="txt_direccion">
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Celular:</label></th>
			<td>
				<div class="input-control text">
					<input type="text" name="txt_telefono" id="txt_telefono" minlength="10" maxlength="10" onKeyPress="return solonumeros(event)">
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Correo:</label></th>
			<td>
				<div class="input-control text">
					<input type="email" name="email" id="email">
				</div>
			</td>
		</tr>
		<tr>
			<th><label class="text-accent">Persona:</label></th>
			<td>
				<div class="imput-control text">
					<input type="text" name="txt_refe" id="txt_refe" minlength="10" maxlength="10" onKeyPress="return solonumeros(event)" >
						</div>
			</td>
		</tr>
 
		<tr>
			<th colspan="2"><button class="button primary rounded" id="btn_guardar" onclick="guardar()"><b><span class="mif-floppy-disk"></span></b> Guardar</button></th>
		</tr>
	</table>
 
	<hr class="bg-grayLighter">
 
	<?php } ?>
 
</body>
 
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
1
Responder
Imágen de perfil de italo_pm
Val: 920
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

obtener el valor del referido

Publicado por italo_pm (193 intervenciones) el 13/04/2019 14:36:21
Hola

para hacer una busqueda o para hacer lo que necesitas a manera de ejemplo y practica empieza por esto, cuando entiendas el mecanismo y en que lugar colocarlo, memorizas $refer y se la pasas a la query como parametro del like.

ejemplo con pdo, adapto a tu lo que necesites..., inicia practicando este codigo para que sepas como funciona la logica.

refer.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
<!-- jquery -->
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
 
<script type="text/javascript">
$(document).ready(function() {
 
	function load_refer(query) {
 
		$.ajax({
			url:"refer_query.php",
			method:"POST",
			data:{query:query},
			success:function(data)
			{
				$('#resultado_busqueda').html(data);
			}
		});
	}
 
	$('#id_refer').keyup(function() {
		var search = $(this).val();
		if(search != '') {
			load_refer(search);
		}
		else {
			$('#resultado_busqueda').html("Buscar Refer");
		}
	});
 
});
</script>
 
	<div class="">
	  <h4>RESULTADO REFER</h3>
		<div class="">
  		<br><span class="">REFER: </span><input type="text" id="id_refer" name="name_refer" class="">
		</div>
	</div>
 
  <div id="resultado_busqueda"></div>

el file config_db_pdo.php contiene la configuracion de conexion a mi db, segun lo que utilizes (pdo, mysqli) adaptas tu file, la logica es la misma.

refer_query.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
<?php
 
//* file config database PDO
include_once  ("../config/config_db_pdo.php");
 
  $refe_input = $_POST['query'];
 
  $refe_like = "%$refe_input %";
 
  $search_query = "select id_referidor, nombre, apellido, from referidor where id_referidor LIKE ?";
 
  $stmt = $pdo->prepare($search_query);
 
  $stmt->execute([$refe_like ]);
 
  $records_num = $stmt->rowCount();
 
  if($records_num > 0) {
 
		while ($row = $stmt->fetch()) {
 
  ?>
      <br><label>Refer - Nombre : <?php echo $row['nombre'];?> Apellido: <?php echo $row['apellido'];?></label>
  <?php
 
    }
 
  } else {
 
    echo '<br> El referidor no existe en la base de datos..';
 
	}
 
?>

prueba en test

si tienes errores escribelos, explicalos y escribe el codigo que utlizaste.

salud2
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar