0

I want to insert data to phymyadmin table using CSV file from front-end of website, which must UPDATE all the record previously in my table.

This code isn't working at all. Please locate the error.

    <?php

   $servername = "localhost";
   $username = "";
             $password = "";
             $dbname = "";

             $conn = mysql_connect($servername, $username , $password );  

              if(! $conn ) {
      die('Could not Find Some Error Occured: ' . mysql_error());
                }

                if(isset($_POST["submit"]))
             {
              if($_FILES['file']['name'])
              {
               $filename = explode(".", $_FILES['file']['name']);
               if($filename[1] == 'csv')
               {
                $handle = fopen($_FILES['file']['tmp_name'], "r");
                while($data = fgetcsv($handle))
                {
                 $uname = mysqli_real_escape_string($connect, $data[0]);  
                 $pass = mysqli_real_escape_string($connect, $data[1]);

                 mysql_select_db('desiresq_record');

            $query = "INSERT into login (username, password)
                               VALUES        ('$uname','$pass')";
                   mysqli_query($connect, $query);
      }
      fclose($handle);
      echo "<script>alert('Import done');</script>";
     }
    }
   }
   ?> 
sahir
  • 1
  • 1
  • you're mixing mysq apis; can't do that and stands to get closed with [Can I mix MySQL APIs in PHP?](http://stackoverflow.com/questions/17498216/can-i-mix-mysql-apis-in-php) – Funk Forty Niner Apr 18 '17 at 14:35

1 Answers1

0

You're using both MySQL and the MySQLi extensions in your script.

I'd suggest just sticking to MySQLi, seeing as MySQL is long deprecated and shouldn't be used due to security issues.

Best of luck!

Thoby
  • 316
  • 1
  • 6