Error downloading the xml file

0
<?php
    error_reporting(E_ALL);
    // Datos de conexión a la base de datos
    require('mysql_connect.script.php');
    $conn = mysql_connect("localhost","root","");
    mysql_select_db("");
    mysqli_set_charset($conexion,"utf8");
    // PARAMETRO ENVIADO 
    $id        = $_GET['id'];
    $PDFtoDwnld = "file.xml";
    $consulta  = "SELECT * FROM detalle3 WHERE id = $id LIMIT 1";
    $resultado = mysqli_query($connexion, $consulta);
    $row       = mysqli_fetch_array($resultado, MYSQLI_ASSOC);
    $contenido = $row["xml"];
    $row        = mysqli_fetch_array($resultado, MYSQLI_ASSOC);
    $PDFtoDwnld = $row["ruc"] ."-". $row["tipdoc"] ."-". $row["serdoc"] ."-". 
 $row["numdoc"].".".substr($header,-3);
    $contenido  = $row[$PDFtoDwnld];
    header("Content-type: application/xml");
    header('Content-disposition: attachment; filename="'.$PDFtoDwnld.'"'); 
    echo $contenido;
?> 

the idea is to download must concatenate RUC-TYPE-SERIES-NUMBER INVOICE

    
asked by Galo Gallardo Mendoza 28.09.2017 в 01:13
source

1 answer

0

At the moment your code has some problems:

  • You are mixing two different extensions : mysql_* (which is obsolete and its use is not recommended) and mysqli . (See Why should not the mysql_ * API be used in PHP / MySQL? )
  • You are losing the value of the xml column. When doing first: $contenido = $row["xml"]; and then $contenido = $row[$PDFtoDwnld]; you are losing the data in the xml column. If you want that data to be in $contenido you must write this: $contenido .= $row[$PDFtoDwnld]; . In PHP it is concatenated by setting .= . If you do not put the point, the variable is initialized and acquires the new value, forgetting the previous one.
  • As I assume you will do, pass all the code to MySQLi and use prepared queries , as this query $consulta = "SELECT * FROM detalle3 WHERE id = $id LIMIT 1"; is vulnerable to SQL injection. (See How to avoid SQL injection in PHP? )
  • answered by 28.09.2017 в 01:25