What is the error in my PHP? [closed]

1
    <?php
 extract($_POST);
    if ($action == "upload") {
        //cargamos el archivo al servidor con el mismo nombre
        //solo le agregue el sufijo bak_ 
        $archivo = $_FILES['excel']['name'];
        $tipo = $_FILES['excel']['type'];
        $destino = "bak_" . $archivo;
        if (copy($_FILES['excel']['tmp_name'], $destino)){
            echo "Archivo Cargado Con Éxito"."<br>";
        }
        else{
            echo "Error Al Cargar el Archivo";
        }


    if (file_exists("bak_" . $archivo)) {
          /** Clases necesarias */
            require_once('Classes/PHPExcel.php');
            require_once('Classes/PHPExcel/Reader/Excel2007.php');

          // Cargando la hoja de cálculo
            $objReader = new PHPExcel_Reader_Excel2007();
            $objPHPExcel = $objReader->load("bak_" . $archivo);
            $objFecha = new PHPExcel_Shared_Date();

           $conexion=mysql_connect("localhost","root","mysql")  or die("Problemas en la conexion");
            mysql_select_db("tef",$conexion) or die("Problemas en la seleccion de la base de datos");

          // Asignar hoja de excel activa
            $objPHPExcel->setActiveSheetIndex(0);


         // Llenamos el arreglo con los datos  del archivo xlsx
            for ($i = 1; $i <= 5; $i++) {
                $_DATOS_EXCEL[$i]['numero_proveedor'] = $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['nombre_proveedor'] = $objPHPExcel->getActiveSheet()->getCell('C' . $i)->getCalculatedValue();
                $_DATOS_EXCEL[$i]['monto_pago'] = $objPHPExcel->getActiveSheet()->getCell('D' . $i)->getCalculatedValue();
            }

        }
        //si por algo no cargo el archivo bak_ 
        else {
            echo "Necesitas primero importar el archivo";
        }
        $errores = 0;
        //recorremos el arreglo multidimensional 
        //para ir recuperando los datos obtenidos
        //del excel e ir insertandolos en la BD
        foreach ($_DATOS_EXCEL as $campo => $valor) {
            $sql = "INSERT INTO tef.archivo VALUES (NULL,'";
            foreach ($valor as $campo2 => $valor2) {
                $campo2 == "direccion" ? $sql.= $valor2 . "');" : $sql.= $valor2 . "','";
            }
            echo $sql;
            $result = mysql_query($sql);
            if (!$result) {
                echo "Error al insertar registro " . $campo;
                $errores+=1;
            }
        }
        echo "<strong><center>ARCHIVO IMPORTADO CON EXITO, EN TOTAL $campo REGISTROS Y $errores ERRORES</center></strong>";
        //una vez terminado el proceso borramos el archivo que esta en el servidor el bak_
        unlink($destino);
    }



?>

I have this code which I ask that you choose an Excel file and when uploading it save the data in my BD. called "tef" in the "file" table

but when uploading the file, this error marks me

  

You have an error in your SQL syntax; review the manual that   corresponds to your version of the MySQL server for the correct syntax   to use near '' on line 1

    
asked by karina reyes 13.07.2018 в 01:57
source

0 answers