Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What i am trying to do upload and then check it before import into my database may be some field need to edit same have wrong (like phone email) for example ...

-----------------------------------------------------------
field 1   | field 2  | field 2  | field 2  | field 2  |
-----------------------------------------------------------
user1data |user1data |user1data |user1data |user1data |
------------------------------------------------------------
user2data |user2data |user2data |user2data |user2data |
----------------------------------------------------------

Now what i did i can upload and it directly upload csv into phpmyadmin .
but what i am tring to do after click upload there should temporary show user1data all data after check it will store in db then user2data come for verification and repeat same think..

here the code I used so far for import csv into db .
PHP
<?php
     include 'db.php';
        if(isset($_POST['submit']))
    {
        $file = $_FILES['file']['tmp_name'];

        $handle = fopen($file, "r");
        while(($fileop = fgetcsv($handle,1000,",")) !== false)
      {
      $IdCorresponsal = $fileop[0];
      $NombreCorresponsal  = $fileop[1];
      $PaisCorresponsal = $fileop[2];
        $ClaveValidacion = $fileop[3];
        $IdGiro = $fileop[4];
        $Fecha = $fileop[5];
        $Hora = $fileop[6];
        $Total = $fileop[7];
        $Moneda = $fileop[8];
        $ClavePago = $fileop[9];
        $Nota = $fileop[10];
        $NombreRte = $fileop[11];
        $Apellido1Rte = $fileop[12];
        $Apellido2Rte = $fileop[13];
        $CiudadRte = $fileop[14];
        $PaisRte = $fileop[15];
        $TipoDocRte = $fileop[16];
        $NumDocRte = $fileop[17];
        $NombreBnf = $fileop[18];
        $Apellido1Bnf = $fileop[19];
        $Apellido2Bnf = $fileop[20];
        $DireccionBnf = $fileop[21];
        $CiudadBnf = $fileop[22];
        $PaisBnf = $fileop[23];
        $Telefono1Bnf = $fileop[24];
        $Telefono2Bnf = $fileop[24];
        $TipoDocBnf = $fileop[26];
        $NumDocBnf = $fileop[27];
        $IdOficina = $fileop[28];
        $NombreOficina = $fileop[29];
        $CodigoOficina = $fileop[30];
        $PagoBanco = $fileop[31];
        $NombreBanco = $fileop[32];
        $DireccionBanco = $fileop[33];
        $NumeroCuenta = $fileop[34];

        $sql = mysql_query("INSERT INTO sampledata (IdCorresponsal,NombreCorresponsal,PaisCorresponsal,ClaveValidacion,IdGiro,Fecha,Hora,Total,Moneda,ClavePago,Nota,NombreRte,Apellido1Rte,Apellido2Rte,CiudadRte,PaisRte,TipoDocRte,NumDocRte,NombreBnf,Apellido1Bnf,Apellido2Bnf,DireccionBnf,CiudadBnf,PaisBnf,Telefono1Bnf,Telefono2Bnf,TipoDocBnf,NumDocBnf,IdOficina,NombreOficina,CodigoOficina,PagoBanco,NombreBanco,DireccionBanco,NumeroCuenta)
        VALUES ('$IdCorresponsal','$NombreCorresponsal','$PaisCorresponsal','$ClaveValidacion','$IdGiro','$Fecha','$Hora','$Total','$Moneda','$ClavePago','$Nota','$NombreRte','$Apellido1Rte','$Apellido2Rte','$CiudadRte','$PaisRte','$TipoDocRte','$NumDocRte','$NombreBnf','$Apellido1Bnf','$Apellido2Bnf','$DireccionBnf','$CiudadBnf','$PaisBnf','$Telefono1Bnf','$Telefono2Bnf','$TipoDocBnf','$NumDocBnf','$IdOficina','$NombreOficina','$CodigoOficina','$PagoBanco','$NombreBanco','$DireccionBanco','$NumeroCuenta')");

        }
    if($sql)

        {
            echo 'Data upload done';

            }
    }
?>

<html>
    <head>
    <meta content="">
    <title>Test</title>

</head>
<body>
<a href="data.php" > See report</a>
 <form method="post" action="index.php" enctype="multipart/form-data">

    <input type="file" name="file" />
    <br>
    <input type="submit" name="submit" value="sumbit" />

    </form>

</body>

</html>
Posted
Updated 10-Feb-14 18:59pm
v2

1 solution

Hello Ahmed,

What you can do is to read/parse the entire file and dump it into the staging table, which will have following additional columns. From this staging table present the data for verification, once user confirms it move it into the live table and delete same from the staging table.

Additional Columns
file_name    VARCHAR(256)
session_id   VARCHAR(20)

Here session_id represents a unique identifier generated per upload. You can also create a filter/search screen if you want using which an authorizer can select a subset.

The code you have presented can be used as is with above column mentioned additions for the upload purpose.


Regards,
 
Share this answer
 
Comments
akankha ahmed 11-Feb-14 1:13am    
hello Prasad Khandekar,
i would like to thank you very much for your time and answer.i am not an expert in php.
add this colus to where
file_name VARCHAR(256)
session_id VARCHAR(20)
Killzone DeathMan 11-Feb-14 12:17pm    
To the database... "ALTER TABLE" and add the columns "file_name" with the type "VARCHAR(256)" and "session_id" with the type "VARCHAR(20)"..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900