-4

I want to import csv data file to masql databse in php.

I want to know which line and column have error on data format

Like row no 24 and column phone no : data is not number .

Please help me plzzzzzzzzz

For example I made this function

function phoneValidate($phone)
{
    global $err;
    if(ctype_digit($phone) && strlen((string)$phone) == 10)
    {
        return 1;
    }
    else
    {

        array_push($err , "phone");
        return 0;
    }
}

I use it in validation

while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
    if(phoneValidate())
empiric
  • 7,825
  • 7
  • 37
  • 48
Durgesh Pandey
  • 119
  • 1
  • 1
  • 11

1 Answers1

0

To specify the position of your error you can simplay use counters:

$i = 1;
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE){
    for ( $x = 0; $x < count ( $emapData ); $x++ )
    {
         if(!validate($emapData[$x])){ //example, $x would be the column
             echo 'Error in line ' . $i . ' on column ' . $x;
         }
    }
    $i++; //row
}

I hope I get it right ...

empiric
  • 7,825
  • 7
  • 37
  • 48