Ok, I've made a page to import my stock file, which is in a .csv
file (which works fine), but after the import is made, the page goes directly to my localhost/index.php
instead of returning the "ok" message... why is that?
here's the code:
<form enctype="multipart/form-data" method="post" role="form">
<div class="form-group">
<label for="exampleInputFile">Importar archivo</label>
<input type="file" name="file" id="file" size="150">
<p class="help-block">Solo archivos .csv</p>
</div>
<button type="submit" class="btn btn-default" name="Import" value="Import">Importar</button>
</form>
<input type="button" onclick=" location.href='http://localhost/inicio.html' " value="Inicio" name="boton" />
<?php
if(isset($_POST["Import"]))
{
//me conecto a la BD
$conexion=mysql_connect("localhost","root","") or die("Problemas en la conexion");
mysql_select_db("kontor",$conexion) or die("Problemas en la seleccion de la base de datos");
echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
$count = 0;
while (($emapData = fgetcsv($file, 10000, ";", '"')) !== FALSE)
{
$count++;
if($count>1){
mysql_query("INSERT into stock (SKU,nombre,descr,prbruto,prneto,fechaing,cantcentral,cantarauco,cantdrug,canttrebol) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]','$emapData[7]','$emapData[8]','$emapData[9]')", $conexion) or die("Problemas en el select: ".mysql_error());
}
}
fclose($file);
echo 'Archivo importado';
header('Location: index.php');
}
else
echo 'Formato de archivo incorrecto';
}
?>
Remove header('Location: index.php');
from your code.
That is causing the redirection.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.