How to validate mobile number in php?

The only way I can think of doing it based on what you show would be to create two arrays at the start of your code, called valid and invalid. As well as adding the valid numbers to the database inside your if() condition, you also add them to the valid array. You add an else() clause to add the invalid numbers to the invalid array. At the end of your code, you loop through each array and display the contents with an appropriate heading.

<?php
include ("connection1.php");
if (isset($_POST["submit"])) {
    // CREATE YOUR TWO ARRAYS HERE
    $file = $_FILES['file']['tmp_name'];
    $handle = fopen($file, "r");
    $c = 0;
    while (($filesop = fgetcsv($handle, 1000, ",")) !== false) {
        $contact = $filesop[0];
        if (preg_match('/(7|8|9)\d{9}/', $contact)) { // phone number is valid
            $sql = mysql_query("INSERT INTO csv1 (contact) VALUES ('$contact')");
            // ADD THE NUMBER TO THE VALID ARRAY
            $c = $c + 1;
        }
        else {
           // ADD THE NUMBER TO THE INVALID ARRAY
          }
       }

       if ($sql) {
          echo "Your Database Has Imported Successfully. You have Inserted " . $c . " Records";
          // ADD SOME CODE HERE TO DISPLAY THE TWO ARRAYS
       } else {
          echo "Sorry! There is a Some Problem.";
       }
    }
?>

If you upload a very large file, you might want to check whether or not something might run out of memory, but then if it’s going to be a really long list, I’m not sure of the value of outputting it. Also note that your check for whether the query worked only checks the status at the end of the while() loop, so you’re only testing to see if the last query in the loop worked, not every one. And you’re still using the old mysql_query call to insert, which is probably not good.