Because after sending variables by ajax and recovering by php, they will fly indefinitely.

1

I have two select and a text box, by means of which I send values to query.php the selected values of the select are the most important for me because it depends on which user selects that values will be passed to some queries with which their value will help to show some graphics. When I do everything through a form with action="php / consultar.php", there is NO problem, but I want the result not to be recharged and shown on the same page.

<?php  
include 'conexion/conexion.php';
$anios_fiscal = "SELECT * FROM periodo ORDER BY nombre_periodo ASC";
$query1 = mysqli_query($conexion_mysql, $anios_fiscal);
$opc_periodo = '<option value="0">Informaci&oacute;n del periodo</option>';
$row_periodo="";
while ($row_periodo = mysqli_fetch_object($query1)){
	$opc_periodo.='<option value="'.$row_periodo->nombre_periodo.'">'.$row_periodo->nombre_periodo.'</option>';
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="alternate" type="text/css" href="css/bootstrap.css">
	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
	<script src="js/jquery.js" type="text/javascript" charset="utf-8" async defer></script>
	<script src="js/jquery.min.js" type="text/javascript" charset="utf-8" async defer></script>
	<script>
		$(document).ready(function(){
    $("#editarot_btn").click(function(){
        var anios_fiscales = $("#anios_fiscales").val();
        var trimestres = $("#trimestres").val();
        var nombre = $("#nombre").val();

        $.ajax({
            type: "POST",
            url: "php/consultar.php",
            data: {anios_fiscales:anios_fiscales, trimestres:trimestres, nombre:nombre},
            success: function(){
                alert("Ha sido ejecutada la acción.");
            }
        });
    });
});
	</script>
</head>
<body>
	<div class="container-fluid">
		<form action="" method="POST" accept-charset="utf-8">
			<div class="row">

				<div class="col-sm-2">
					<select class="form-control" name="anios_fiscales" id="anios_fiscales">
						<?php echo $opc_periodo; ?>
					</select>				
				</div>

				<div class="col-sm-2">
					<select class="form-control" name="trimestres" id="trimestres">
						<option value="Q-1">Trimestre 1</option>
						<option value="Q-2">Trimestre 2</option>
						<option value="Q-3">Trimestre 3</option>
						<option value="Q-4">Trimestre 4</option>
					</select>
				</div>

				<div class="col-sm-4">
					<input type="text" name="nombre" id="nombre" class="form-control nombre">
				</div>

				<div class="col-sm-4">
					<button type="button" id="editarot_btn" class="btn btn-success editarot_btn">Consultar 
						<span class="glyphicon glyphicon-send"></span>
					</button>					
				</div>
			</div>

		</form>

	</div>
	<div id="contenedor"></div>


</body>
</html>
<!-- <script src="js/funciones.js" type="text/javascript" charset="utf-8" async defer></script> -->

Here is the query code.php.

<?php  
include '../conexion/conexion.php';
$anios_fiscal_ = $_POST["anios_fiscales"];
$periodo = $_POST["trimestres"];
$text = $_POST["nombre"];
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
<body>
	<div id="contenedor">
		<h1>hola</h1>
		<?php 
		echo $anios_fiscal_; 
		echo "<br>";
		echo $periodo;
		echo "<br>";
		echo $text;
		echo "<br>";
		$don_nac_id50 = "SELECT respuesta FROM respuestas WHERE oficina='UP4' AND periodo='$anios_fiscal_' AND trimestre='$periodo' AND id='RRHH2_ID23'";
		$result_nac_id50 = mysqli_query($conexion_mysql, $don_nac_id50);
		if ($fila=mysqli_fetch_object($result_nac_id50)) {echo $respuesta_don_nac_id50_Q1 = $fila->respuesta;}
		echo "<br>";
		$don_nac_Q2 = "SELECT respuesta FROM respuestas WHERE id='DonNac_ID50' AND oficina='OCD' AND periodo='$anios_fiscal_' AND trimestre='$periodo'";
		$result_nac_Q2 = mysqli_query($conexion_mysql, $don_nac_Q2);
		if ($fila=mysqli_fetch_object($result_nac_Q2)) {echo $respuesta_don_nac_id50_Q2 = $fila->respuesta;}
		echo "<br>";
		echo $total = (($respuesta_don_nac_id50_Q1/$respuesta_don_nac_id50_Q2)*100);
		echo "<br>";
		$don_nac_Q3 = "SELECT respuesta FROM respuestas WHERE id='DonNac_ID50' AND oficina='OCD' AND periodo='$anios_fiscal_' AND trimestre='$periodo'";
		$result_nac_Q3 = mysqli_query($conexion_mysql, $don_nac_Q3);
		if ($fila=mysqli_fetch_object($result_nac_Q3)) {echo $respuesta_don_nac_id50_Q3 = $fila->respuesta;}
		echo "<br>";
		$don_nac_Q4 = "SELECT respuesta FROM respuestas WHERE id='DonNac_ID51' AND oficina='OCD' AND periodo='$anios_fiscal_' AND trimestre='$periodo'";
		$result_nac_Q4 = mysqli_query($conexion_mysql, $don_nac_Q4);
		if ($fila=mysqli_fetch_object($result_nac_Q4)) {echo $respuesta_don_nac_id50_Q4 = $fila->respuesta;}
		echo "<bR>";
		echo $total2 = (($respuesta_don_nac_id50_Q3/$respuesta_don_nac_id50_Q4)*100);;
		?>
		<div style="width: 600px; height: 400px; margin: 0 auto">
    		<div id="container-speed" style="width: 300px; height: 200px; float: left"></div>
    		<div id="container-rpm" style="width: 300px; height: 200px; float: left"></div>
		</div>
	</div>
</body>
</html>

The result I get makes me see that my variables are not defined, please I need help.

This is a result that I see on the screen, where the errors must show the selected values.

    
asked by Julio Flores 13.03.2018 в 23:26
source

0 answers