PHP - consulta php

 
Vista:
sin imagen de perfil

consulta php

Publicado por andres (15 intervenciones) el 21/08/2017 02:18:52
Buenas noches

tengo un error en la consultas al editar y eliminar

no logro encontrar el error, ya que llevo días buscándolo
conexion.php
1
2
3
4
5
6
7
8
9
10
<?php
 
	$mysqli = new mysqli('localhost', 'root', '', 'encuesta');
 
	if($mysqli->connect_error){
 
		die('Error en la conexion' . $mysqli->connect_error);
 
	}
?>

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
<?php
	require 'conexion.php';
 
	$sql = "SELECT * FROM preguntas where id_dimension_p = 1";
    $sql1 = "SELECT * FROM dimension where id_dimension = 1";
    mysqli_query($mysqli,"SET NAMES 'utf8'");
	$resultado = $mysqli->query($sql);
    $resultado1 = $mysqli->query($sql1);
 
 
?>
<html lang="es">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/bootstrap-theme.css" rel="stylesheet">
		<script src="js/jquery-3.1.1.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</head>
 
	<body>
 
		<div class="container">
			<div class="row">
				<h2 style="text-align:center">Administrador de encuesta</h2>
			</div>
 
			<div class="row">
				<a href="nuevo.php" class="btn btn-primary">Nueva pregunta</a>
			</div>
 
			<br>
 
			<div class="row table-responsive">
				<table class="table table-striped">
					<thead>
						<tr>
							<?php while($row = $resultado1->fetch_array(MYSQLI_ASSOC)) { ?>
							<th><?php echo $row['nombre_dimension']; ?></th>
						    <?php } ?>
 
 
							<th></th>
							<th></th>
						</tr>
					</thead>
 
					<tbody>
						<?php while($row = $resultado->fetch_array(MYSQLI_ASSOC)) { ?>
							<tr>
								<td><?php echo $row['nombre']; ?></td>
								<td><a href="modificar.php?id=<?php echo $row['id_pregunta']; ?>"><span class="glyphicon glyphicon-pencil"></span></a></td>
								<td><a href="#" data-href="eliminar.php?id=<?php echo $row['id_pregunta']; ?>" data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash"></span></a></td>
							</tr>
						<?php } ?>
					</tbody>
				</table>
			</div>
		</div>
 
		<!-- Modal -->
		<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
 
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title" id="myModalLabel">Eliminar Registro</h4>
					</div>
 
					<div class="modal-body">
						¿Desea eliminar este registro?
					</div>
 
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
						<a class="btn btn-danger btn-ok">Delete</a>
					</div>
				</div>
			</div>
		</div>
 
		<script>
			$('#confirm-delete').on('show.bs.modal', function(e) {
				$(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
 
				$('.debug-url').html('Delete URL: <strong>' + $(this).find('.btn-ok').attr('href') + '</strong>');
			});
		</script>
 
	</body>
</html>


eliminar.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
<?php
 
	require 'conexion.php';
 
	$id = $_GET['id_pregunta'];
 
	$sql = "DELETE FROM preguntas WHERE id_pregunta = '$id'";
	$resultado = $mysqli->query($sql);
 
?>
 
<html lang="es">
	<head>
 
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/bootstrap-theme.css" rel="stylesheet">
		<script src="js/jquery-3.1.1.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</head>
 
	<body>
		<div class="container">
			<div class="row">
				<div class="row" style="text-align:center">
				<?php if($resultado) { ?>
				<h3>REGISTRO ELIMINADO</h3>
				<?php } else { ?>
				<h3>ERROR AL ELIMINAR</h3>
				<?php } ?>
 
				<a href="index.php" class="btn btn-primary">Regresar</a>
 
				</div>
			</div>
		</div>
	</body>
</html>

modificar
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
<?php
	require 'conexion.php';
 
	$id = $_GET['id_pregunta'];
 
	$sql = "SELECT * FROM preguntas WHERE id_pregunta = '$id' ";
	$resultado = $mysqli->query($sql);
	$row = $resultado->fetch_array(MYSQLI_ASSOC);
 
?>
<html lang="es">
	<head>
 
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/bootstrap-theme.css" rel="stylesheet">
		<script src="js/jquery-3.1.1.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</head>
 
	<body>
		<div class="container">
			<div class="row">
				<h3 style="text-align:center">MODIFICAR REGISTRO</h3>
			</div>
 
			<form class="form-horizontal" method="POST" action="update.php" autocomplete="off">
				<div class="form-group">
					<label for="nombre" class="col-sm-2 control-label">Nombre</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" id="nombre" name="nombre" placeholder="Nombre" value="<?php echo $row['nombre']; ?>" required>
					</div>
				</div>
 
				<input type="hidden" id="id_pregunta" name="id_pregunta" value="<?php echo $row['id_pregunta']; ?>" />
 
 
 
 
 
 
 
 
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-10">
						<a href="index.php" class="btn btn-default">Regresar</a>
						<button type="submit" class="btn btn-primary">Guardar</button>
					</div>
				</div>
			</form>
		</div>
	</body>
</html>

update.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
<?php
 
	require 'conexion.php';
 
	$id = $_POST['id_pregunta'];
	$nombre = $_POST['nombre'];
 
 
	$sql = "UPDATE preguntas SET nombre='$nombre' WHERE id_pregunta = '$id'";
	$resultado = $mysqli->query($sql);
 
?>
 
<html lang="es">
	<head>
 
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/bootstrap-theme.css" rel="stylesheet">
		<script src="js/jquery-3.1.1.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</head>
 
	<body>
		<div class="container">
			<div class="row">
				<div class="row" style="text-align:center">
				<?php if($resultado) { ?>
				<h3>REGISTRO MODIFICADO</h3>
				<?php } else { ?>
				<h3>ERROR AL MODIFICAR</h3>
				<?php } ?>
 
				<a href="index.php" class="btn btn-primary">Regresar</a>
 
				</div>
			</div>
		</div>
	</body>
</html>


eliminarerror
updateerror

Adjunto la base de datos

si me pudieran ayudar se los agradecería muchas gracias
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
Imágen de perfil de Hector
Val: 26
Ha aumentado su posición en 4 puestos en PHP (en relación al último mes)
Gráfica de PHP

consulta php

Publicado por Hector (20 intervenciones) el 09/09/2017 01:36:53
Hola, creo que es porque envias el parametro por GET con el nombre de id pero en tu archivo php dice id_pregunta..

Fijate....

Asi lo envias fijate bien lo que subrayé
Captura

y lo recibes así

Captura1

En fin, creo que el código de tus botones debería quedar de la siguiente manera.

1
2
<td><a href="modificar.php?id_pregunta=<?php echo $row['id_pregunta']; ?>"><span class="glyphicon glyphicon-pencil"></span></a></td>
	  <td><a href="#" data-href="eliminar.php?id_pregunta=<?php echo $row['id_pregunta']; ?>" data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash"></span></a></td>

Avisame como te fué..
Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar