I have a small script that calls a PHP file but it does not work for me, it throws 500 error by the Chrome console ...
The idea is that when you select an element in a textlist, then execute the PHP code and print it inside a table that has its respective ID ... the script is:
<script type="text/javascript">
$(document).ready(function(){
$("#codigo").change(function(){
$.get("admin/actions/checkbox_mantenimiento.php","codigo="+$("#codigo").val(), function(data){
$("#tipos_mant").html(data);
console.log(data);
});
});
});
</script>
And the PHP is as follows:
<?php
include("config.php");
if(isset($_GET['codigo']))
{
$codigoequipo=$_GET['codigo'];
if($codigoequipo=="") {
echo "Ningún equipo seleccionado.";
}
else {
$consulequipo = "SELECT * FROM maquinarias WHERE serialequipo = '$codigoequipo'";
$consultipos = "SELECT * FROM mantenimiento WHERE codigo = '$codigoequipo'";
$equipo = $bd->consulta($consulequipo);
$tipos = $bd->consulta($consultipos);
if ($rowtipos = $tipos->fetch_assoc() && $rowequipo = $equipo->fetch_assoc()) {
$cantidadcb = $rowtipos['nro_tipos'];
$checkboxes = while ($trigger < $cantidadcb) {
echo "
<tr>
<td width=\"50%\">
<input class=\"form-control\" type=\"checkbox\" value=\"".$rowtipos['tipo'.$trigger]."required name=\"op_".$trigger."\">
</td>
</tr>";
$trigger++;
}
echo "
<form role=\"form\" action=\"?admin=mperiod&crearperiod=crearperiod\" method=\"post\" enctype=\"multipart/form-data\">
<thead>
<tr>
<th>Código</th>
</tr>
</thead>
<tbody>
<tr colspan=\"2\" width=\"50%\">
<td>
<input type=\"text\" class+\"form-control\" value=\"".$rowequipo['serialequipo']."\" name=\"codigo\" readonly required>
</td>
</tr>
<tbody>
<thead>
<tr>
<th>Tipos de Mantenimiento Asociados</th>
<tr>
<thead>
<tbody>
".$checkboxes."
<tbody>
<tr>
<td width=\"100%\" colspan=\"2\"><center>
<button type=\"submit\" class=\"btn btn-primary btn-lg\" name=\"lugarguardar\" value=\"Guardar\">Registrar</button></center>
</td>
</tr>
</tbody>
</form>";
}
}
}
?>
If you need something additional I am ready to provide what is necessary. Thanks in advance for everything.