php - Replacing values using .csv file -


i'm building schedule board our university. i'm done uploading .csv file , showing data. problem is, there way can replace whole data i've uploaded before in uploading new .csv file? mean delete/replace old data..

this php code upload csv file.

<?php  $conn = mysql_connect("localhost","root","") or die (mysql_error());  mysql_select_db("testing",$conn);   if(isset($_post['submit']))  {     $file = $_files['file']['tmp_name'];      if($file == "")     {         ?>         <script type="text/javascript">         alert('no file selected!');         </script>         <?php     }         else     {     $handle = fopen($file,"r");      while(($fileop = fgetcsv($handle,1000,",")) !==false)     {         $subj_desc = $fileop[0];         $subj_code = $fileop[1];         $units = $fileop[2];         $day = $fileop[3];         $start_time = $fileop[4];         $end_time = $fileop[5];         $soc = $fileop[6];         $eoc = $fileop[7];         $max = $fileop[8];         $room = $fileop[9];         $term = $fileop[10];         $lecturer = $fileop[11];          $sql = mysql_query("insert `tbl_schedule_board` (`subj_desc`,`subj_code`,`units`,`day`,`start_time`,`end_time`,`soc`,`eoc`,`max`,`room`, `term`, `lecturer`)         values (                 '" . mysql_real_escape_string($subj_desc) . "',                 '" . mysql_real_escape_string($subj_code) . "',                 '" . mysql_real_escape_string($units) . "',                 '" . mysql_real_escape_string($day) . "',                 '" . mysql_real_escape_string($start_time) . "',                 '" . mysql_real_escape_string($end_time) . "',                 '" . mysql_real_escape_string($soc) . "',                 '" . mysql_real_escape_string($eoc) . "',                 '" . mysql_real_escape_string($max) . "',                 '" . mysql_real_escape_string($room) . "',                 '" . mysql_real_escape_string($term) . "',                 '" . mysql_real_escape_string($lecturer) . "')");     }      if($sql)      {         echo '<script> alert("data uploaded."); </script>';      }     } } 

?>

any appreciated. thank you!

if want delete all old data table use truncate command:

truncate table `users_sched`; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -