Good afternoon. I do not know why this query is not done in PHP and Mysql
This is the code of the form to send the content:
<?php
session_start();
if(!isset($_SESSION['usuario']))
{
header('Location:auth');
exit();
}
include 'conexion.php';
$usuario = $_SESSION['usuario'];
//Consulta numero de mensajes
$grupo= $_GET['grupo'];
$iii="1";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Software Benedicto XVI | Software Eclesiástico SisPasIn</title>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="css/dataTables.bootstrap.min.css" />
<script src="js/bootstrap.min.js"></script>
<script src="js/FancyZoom.js" type="text/javascript"></script>
<script src="js/FancyZoomHTML.js" type="text/javascript"></script>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#seminaristas').DataTable();
rowReorder: true
} );
$(document).ready(function() {
$('#mensajes').DataTable();
rowReorder: true
} );
</script>
<body onLoad="setupZoom()">
<div class="container">
<center><h1> <font face="Trajan Pro">Resultados</font></h1></center>
<a href="index.php"><button type="button" class="btn btn-default"> Regresar</button></a></br></br>
<form method="post" name="actualizar" id="actualizar" action="actualizar.php">
<table id="seminaristas" class="table table-striped table-bordered" cellspacing="0" >
<thead>
<tr>
<th>Apellidos, Nombre</th>
<?php
$sentencia=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
While($resultado=mysqli_fetch_array($sentencia)){
?>
<th><?php echo $resultado['nombre_calificacion']; ?> (<?php echo $resultado['porcentaje']; ?>%)</th>
<?php } ?>
</thead>
<tfoot>
<tr>
<th>Apellidos, Nombre</th>
<?php
$sentencia=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$numero = mysqli_num_rows($sentencia);
While($resultado=mysqli_fetch_array($sentencia)){
?>
<th><?php echo $resultado['nombre_calificacion']; ?> (<?php echo $resultado['porcentaje']; ?>%)</th>
<?php } ?>
</tr>
</tfoot>
<tbody>
<?php //carga los nombres
$ss=mysqli_query($conexion,"SELECT * FROM seminaristas JOIN grupo_estudiante WHERE grupo_estudiante.Idg='$grupo' AND grupo_estudiante.Id=seminaristas.Id ORDER BY seminaristas.apellido, seminaristas.nombre ASC");
$ii="1";
While($rr=mysqli_fetch_array($ss)){
?>
<tr>
<td><?php echo $rr['apellido']; ?>, <?php echo $rr['nombre']; ?></td>
<?php
$sentencia2=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$i="1";
While($resultado2=mysqli_fetch_array($sentencia2)){
$numero_cali=$resultado2['Idcal'];
$estudiante=$rr['Id'];
$sentencia3=mysqli_query($conexion,"SELECT * FROM notas WHERE calificacion='$numero_cali' AND estudiante='$estudiante' AND grupo='$grupo'");
$resultado3=mysqli_fetch_assoc($sentencia3);
?>
<td><input name="nota<?php echo $i; ?>[]" data-id="<?php echo $estudiante; ?>" id="nota<?php echo $i; ?>-<?php echo $estudiante; ?>" value="<?php echo $resultado3['nota']; ?>" /> <input data-id="<?php echo $estudiante; ?>" id="porcentaje<?php echo $i; ?>-<?php echo $estudiante; ?>" style="display:none" value="<?php echo $resultado2['porcentaje']; ?>" /> <input name="idnota<?php echo $i; ?>[]" id="idnota<?php echo $i; ?>-<?php echo $estudiante; ?>" style="display:none" value="<?php echo $resultado3['Idn']; ?>" /></td>
<td hidden><input name="idn[]" id="<?php echo $iii; ?>" value="<?php echo $iii; ?>" /></td>
<td hidden><input name="grupo" id="grupo" value="<?php echo $grupo; ?>" /></td>
<?php $i++; $iii++; } ?>
<td><input name="resultado[]" id="resultado-<?php echo $estudiante; ?>" value="0" readonly /></td>
<?php $ii++; } ?>
</tr>
</table>
</th>
<input type="submit" name="actualizar" value="Guardar" class="btn btn-info col-md-offset-9" />
</form>
</div>
<script src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$('input').click(function() {
$(this).select();
});
$(document).ready(function(){
$("#actualizar").find(':input').each(function() {
var elemento= this;
var dataid = $(this).data('id');
<?php
$sentencia2=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$i="1";
While($resultado2=mysqli_fetch_array($sentencia2)){
?>
var nota<?php echo $i; ?> = parseFloat($('#nota<?php echo $i; ?>-' + dataid).val());
var porcentaje<?php echo $i; ?> = parseFloat($('#porcentaje<?php echo $i; ?>-' + dataid).val());
<?php $i++; } ?>
var resultado = <?php $sentencia22=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$i="1";
$numero = mysqli_num_rows($sentencia22);
While($resultado22=mysqli_fetch_array($sentencia22)){
?>(nota<?php echo $i; ?>*porcentaje<?php echo $i; ?>/100) <?php if ($i < $numero) { echo "+"; } else { echo ""; } ?> <?php $i++; } ?>
$('#resultado-' + dataid).val(resultado);
});
});
$('input').keyup(function() {
var dataid = $(this).data('id');
<?php
$sentencia23=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$i="1";
While($resultado23=mysqli_fetch_array($sentencia23)){
?>
var nota<?php echo $i; ?> = parseFloat($('#nota<?php echo $i; ?>-' + dataid).val());
var porcentaje<?php echo $i; ?> = parseFloat($('#porcentaje<?php echo $i; ?>-' + dataid).val());
<?php $i++; } ?>
var resultado = <?php $sentencia22=mysqli_query($conexion,"SELECT * FROM calificaciones WHERE grupo='$grupo'");
$i="1";
$numero = mysqli_num_rows($sentencia22);
While($resultado22=mysqli_fetch_array($sentencia22)){
?>(nota<?php echo $i; ?>*porcentaje<?php echo $i; ?>/100) <?php if ($i < $numero) { echo "+"; } else { echo ""; } ?> <?php $i++; } ?>
$('#resultado-' + dataid).val(resultado);
})
</script>
</body>
</html>
And this is the code that executes the query.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
include 'conexion.php';
$grupo= $_POST['grupo'];
$i="1";
if(isset($nota[$i]))
{
for ($i = 1; $i < count($_POST['idn']); $i++)
{
$sentencia23=mysqli_query(
$conexion,
"SELECT * FROM calificaciones WHERE grupo='$grupo'"
);
$numero = mysqli_num_rows($sentencia23);
$ii='1';
$nota='nota';
$idnota='idnota';
$stmt = $mysqli->prepare("UPDATE notas SET nota = ? WHERE Idn = ?");
while ($resultado23 = mysqli_fetch_array($sentencia23))
{
${$nota.''.$ii} = $_POST[$nota.''.$ii][$i];
${$idnota.''.$ii} = $_POST[$idnota.''.$ii][$i];
//$result = $conexion->query(
// "UPDATE notas SET nota = \'$nota.''.$ii\' WHERE Idn = \''$idnota.''.$ii'\'"
//);
$stmt->bind_param(
'ss',
$_POST[$nota.''.$ii][$i],
$_POST[$idnota.''.$ii][$i]
);
$stmt->execute();
$ii++;
}
}
}
//Comprobación de la actualización
$res = ($resultado = $conexion->query($stmt))
? "Los datos han sido actualizados satisfactoriamente."
: "Intente nuevamente, no se ha podido ejecutar la actualización."
. $ejecucion->error;
/*
//Comprobación de la actualización
if ($resultado = $conexion->query($stmt))
{
$res = "Los datos han sido actualizados satisfactoriamente.";
}
else
{
$res = "Intente nuevamente, no se ha podido ejecutar la actualización." . $ejecucion->error;
}
*/
mysqli_close($conexion);
echo $res;
?>
</html>
The errors that appear are:
Notice: Undefined variable: stmt in C: \ xampp \ htdocs \ seminar \ academy \ update.php on line 35
Warning: mysqli :: query (): Empty query in C: \ xampp \ htdocs \ seminar \ academy \ update.php on line 35
Notice: Undefined variable: execution in C: \ xampp \ htdocs \ seminar \ academy \ update.php on line 38
Notice: Trying to get property of non-object in C: \ xampp \ htdocs \ seminar \ academy \ update.php on line 38 Try again, the update could not be executed.
Thank you very much.