Cordial greeting. I'm new to this programming and I'm doing a page in wordpress that performs a query in SQL Server and sends the data to a table.
By clicking on the "Consult" button, the page is redirected to a 404 because it does not process or send the variable value. Also in the SQL query it returns a Warning because it is unknown the value of the name variable
This is the code I'm using.
accept
Hello and thanks for the answers.
I suppose I must validate first so that the first time you load the page, make the query, but even if I put the validation at the beginning, it generates a warning:
Warning: mssql_query (): message: Incorrect syntax near the keyword 'order'. (severity 15) in /var/www/html/intraser/wp-content/plugins/exec-php/includes/runtime.php(42): eval () 'd code on line 89
And clicking on consult continues redirecting to a 404. Effectively I need the result of the query to load it on the same page in an HTML table to be able to export to an XLS later.
I send the code again waiting for some other idea about what is happening. Thanks again for collaborating.
<?php if(isset($_POST['name'])){ $name = $_POST['name']; } ?>
<div>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>">
<div>
Seleccione periodo:
<select name="name">
<option value="0" selected>Haga clic aquí</option>
<option value="1" <?php if($_POST['name']=='1') echo 'selected="selected" ';?>> ENERO</option>
<option value="2" <?php if($_POST['name']=='2') echo 'selected="selected" ';?>>FEBRERO</option>
<option value="3" <?php if($_POST['name']=='3') echo 'selected="selected" ';?>>MARZO</option>
<option value="4" <?php if($_POST['name']=='4') echo 'selected="selected" ';?>>ABRIL</option>
<option value="5" <?php if($_POST['name']=='5') echo 'selected="selected" ';?>>MAYO</option>
<option value="6" <?php if($_POST['name']=='6') echo 'selected="selected" ';?>>JUNIO</option>
<option value="7" <?php if($_POST['name']=='7') echo 'selected="selected" ';?>>JULIO</option>
<option value="8" <?php if($_POST['name']=='8') echo 'selected="selected" ';?>>AGOSTO</option>
<option value="9" <?php if($_POST['name']=='9') echo 'selected="selected" ';?>>SEPTIEMBRE</option>
<option value="10" <?php if($_POST['name']=='10') echo 'selected="selected" ';?>>OCTUBRE</option>
<option value="11" <?php if($_POST['name']=='11') echo 'selected="selected" ';?>>NOVIEMBRE</option>
<option value="12" <?php if($_POST['name']=='12') echo 'selected="selected" ';?>>DICIEMBRE</option>
</select>
<input type="submit" name="submit" value="Consultar">
<input type="button" onclick=" generateexcel('testTable') " value="Exportar a Excel">
</div>
</form>
</div>
<?php
echo "<table class='peq' id='testTable'>";
echo "<tr>";
echo "<th class='peq'>Codigo</th>";
echo "<th class='peq'>Apellidos</th>";
echo "<th class='peq'>Nombres</th>";
echo "<th class='peq'>Fecha_nacimiento</th>";
echo "<th class='peq'>Direccion_domicilio</th>";
echo "<th class='peq'>Ciudad</th>";
echo "</tr>";
$name = $_POST['name'];
ini_set('mssql.charset', 'UTF-8');
$msconnect=mssql_connect("ECOSOL","logfuncionario","F3s3r2017_");
$msdb=mssql_select_db("solido",$msconnect);
$msquery = "Select
asociados.codigo,
asociados.nombre,
asociados.apellido,
(CONVERT (char(10),asociados.fecha_nacimiento, 103)) as fecha_nacimiento,
asociados.direccion,
asociados.ciudad
from (
SELECT
CAST(CAST(sys_maenit.CODIGOTER AS float(53)) AS decimal(10, 0))as codigo,
sys_maenit.APELLIDO AS apellido,
sys_maenit.NOMBRE AS nombre,
sys_maenit.DIRECCION AS direccion,
sys_ciudad57.NOMBRE_CIUDAD AS ciudad,
sys_maenit.FECNACEM as fecha_nacimiento,
sys_maenit.empresa as empresa
FROM (solido.dbo.sys_maenit
CROSS JOIN solido.dbo.sys_ciudad57)
WHERE (
(sys_maenit.ESTADO = 'A') AND
(sys_maenit.CLASE = '5') AND
(sys_maenit.DPTO_CIUDAD = sys_ciudad57.CIUDAD))
) as asociados
where asociados.empresa != '0099'
and month(asociados.fecha_nacimiento)=".$name." order by day(asociados.fecha_nacimiento);";
$msresults= mssql_query($msquery);
while ($row = mssql_fetch_array($msresults)){
echo "<tr>";
echo "<td class='peq'>$row[0]</td>";
echo "<td class='peq'>$row[1]</td>";
echo "<td class='peq'>$row[2]</td>";
echo "<td class='peq'>$row[3]</td>";
echo "<td class='peq'>$row[4]</td>";
echo "<td class='peq'>$row[5]</td>";
echo "</tr>";
}
echo "</table>";
?>
Thank you for your kind cooperation