PHP - Ajax me impide...

 
Vista:

Ajax me impide...

Publicado por Jorge (1 intervención) el 26/04/2022 01:27:23
Hola buenas, me encontraba programando esta parte de mi pagina web pero me parece que ajax me impide el alterar la base de datos, no e encontrado nada acerca de ello pero si alguien tuviese la respuesta se lo agradecería.
Por cierto no es nada de la base de datos pues otras paginas con la misma configuración para la base si hace consultas y todo pero no usan ajax.
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
//Pagina de pedidos
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
	<script type="text/javascript">
		function actualizacion(){
			var tabla = $.ajax({
				url:'tablapedidos.php',
				dataType: 'text',
				async:false
			}).responseText;
			document.getElementById("mitabla").innerHTML = tabla;
		}
		setInterval(actualizacion,500);
	</script>
	<link rel="stylesheet" href="../CSS/estilos.css">
	<link rel="icon" href="../IMG/logocftys.png">
	<title>COFFETYS</title>
</head>
<a href="../ADM/vistaadmin.php" style="text-decoration: none; color: black;"><header class="encabezado"><h2>COFFETYS</h2></header></a>
 
	<button id="mostrar-nav"><img src="../IMG/gifcoffetys.gif" width="100%" height="100%"></button><a href="perfilad.php"><button class="perfil"><img src="../IMG/perfil.png" width="100%" height="100%"></button></a>
		<nav>
		<ul class="menu">
			<li><a href="pedidosad.php"><img src="../IMG/pedidos.png" width="20%" height="20%">Pedidos</a></li>
			<li style="line-height: 110%"><a href="#"><img src="../IMG/almacen.png" width="20%" height="20%">Almacen</a></li>
			<li><a href="#"><img src="../IMG/anuncio.png" width="20%" height="20%">Anuncios</a></li>
			<li ><a href="#"><img src="../IMG/abastecimiento.png" width="20%" height="20%">Abastecer</a></li>
			<li style="line-height: 110%"><a href="../USU/Salir.php"><img src="../IMG/cerrar-sesion.png" width="20%" height="20%">Cerrar ...Sesion</a></li>
		</ul>
	</nav>
<body>
	<section id="mitabla" class="tablaad">
 
	</section>
 
<script src="../JSCR/scriptVent.js"></script>
<script src="../JSCR/scriptMenu.js"></script>
</body>
</html>
//Pagina de la tabla
<?php session_start();
		include("../JSCR/Conexion1.php");
		echo "
		<link rel='stylesheet' href='../CSS/estilos.css'>
				<center><table class='tabla'>
				<thead>
				<tr>
				<th>ID</th>
				<th>Nombre</th>
				<th>Boleta</th>
				<th>Total</th>
				<th>Acciones</th>
				</tr>
				</thead>
				<tbody>";
		$consulta = "SELECT * FROM pedidos WHERE Estado = 0";
		$datos = $conexion ->query($consulta);
			if (isset($datos)) {
				$i = 0;
				while ($valores = $datos ->fetch_array(MYSQLI_BOTH)) {
					$pedidos[$i] = $valores;
					$i++;
					}
			$registros = count($pedidos);
			$pedidos[$registros] = 0;
			$a = 0;
			$b = 0;
			$total = 0;
			$numero = 1;
			while ($a < $registros) {
				if (isset($pedidos[$b])) {
					if ($pedidos[$a]['IDpedido'] == $pedidos[$b]['IDpedido']) {
						$total += $pedidos[$b]['TotalCompra'];
						$b++;
					}else{
						$id = $pedidos[$b-1]['IDpedido'];
						$nombre = $pedidos[$b-1]['NombreAl'];
						$boleta = $pedidos[$b-1]['Boleta'];
						echo "<tr>
								<form action='valped.php' method='post'>
								<th>$id</th>
								<th>$nombre</th>
								<th>$boleta</th>
								<th>$total</th>
								<input type='hidden' name='ID' value='$id'>
								<input type='hidden' name='BL' value='$boleta'>
								<th style='display:flex;'>
								<button style='background:transparent; border: none; cursor: pointer;'  type='submit'
								name='si' value= 1><img src='../IMG/aceptar.png' width='30px'></button>
								<button style='background:transparent; border: none; cursor: pointer;'type='submit'
								name='no' value= 1><img src='../IMG/cancelar1.png' width='30px'></button>
								<a href='info.php'><button style='background:transparent; border: none; cursor: pointer;'>
								<img src='../IMG/ver.png' width='30px'></button></a></th>
								</form></tr>";
						$a = $b;
						$total = 0;
						$numero ++;
					}
					}elseif (!isset($pedidos[$b])) {
						if (isset($pedidos[$a]['IDpedido'])) {
							$id = $pedidos[$b-1]['IDpedido'];
							$nombre = $pedidos[$b-1]['NombreAl'];
							$boleta = $pedidos[$b-1]['Boleta'];
							echo "<tr>
								<form action='valped.php' method='post'>
								<th>$id</th>
								<th>$nombre</th>
								<th>$boleta</th>
								<th>$total</th>
								<input type='hidden' name='ID' value='$id'>
								<input type='hidden' name='BL' value='$boleta'>
								<th style='display:flex;'>
								<button style='background:transparent; border: none; cursor: pointer;'  type='submit' name='si' value= 1 >
								<img src='../IMG/aceptar.png' width='30px'></button>
								<button style='background:transparent; border: none; cursor: pointer;'type='submit' name='no' value= 1>
								<img src='../IMG/cancelar1.png' width='30px'></button>
								<a href='info.php'><button style='background:transparent; border: none cursor: pointer;;'>
								<img src='../IMG/ver.png' width='30px'></button></a></th>
								</form></tr>";
						}
						else
						{
							echo "<br><br><br><br>0000000000000000";
						}
 
					}
			}
		}
 
	echo "</table></center>";
?>
//Pagina de acciones para los botones
<?php session_start();
$id = $_POST['ID'];
$boleta = $_POST['BL'];
$consulta = "SELECT Estado FROM pedidos WHERE IDpedido = '$id' and Boleta = '$boleta'";
$datos = $conexion ->query($consulta);
$i = 0;
while ($valores = $datos ->fetch_array(MYSQLI_BOTH)) {
	$pedidos[$i] = $valores;
	$i++;
	}
	echo "$pedidos[9]";
if ($pedidos[0] == 0) {
	if (isset($_POST['si'])) {
		$actualizar  = "UPDATE pedidos SET Estado = '1' WHERE IDpedido = '$id' and Boleta = '$boleta'";
		$ejecutar = mysqli_query($conexion, $actualizar);
		echo "Hola";
	}elseif (isset($_POST['no'])) {
		$actualizar  = "UPDATE pedidos SET Estado = '0' WHERE IDpedido = '$id' and Boleta = '$boleta'";
		$ejecutar = mysqli_query($conexion, $actualizar);
		echo "Hola";
	}
}
if ($pedidos[0] == 1) {
	if (isset($_POST['si'])) {
		$actualizar  = "UPDATE pedidos SET Estado = '2' WHERE IDpedido = '$id' and Boleta = '$boleta'";
		$ejecutar = mysqli_query($conexion, $actualizar);
	}elseif (isset($_POST['no'])) {
		$actualizar  = "UPDATE pedidos SET Estado = '1' WHERE IDpedido = '$id' and Boleta = '$boleta'";
		$ejecutar = mysqli_query($conexion, $actualizar);
	}
}
 
header("Location: ".$_SERVER['HTTP_REFERER']."");
?>
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