1

i am reading data from .txt file and inserting it into database in php.I want to do that whenever the code read one line the $flag variable should change to 0 for each line,and it should write it to a .txt file.

my php script

  $open = fopen('py_txt.txt','r');
  while (!feof($open)) {
$getTextLine = fgets($open);
$explodeLine = explode(",",$getTextLine);

list($value1,$value2,$value3,$value4,$value5,$value6,$value7,$flag) = $explodeLine;
if($flag!=0){
$qry = "insert into table1 (col1, col2,col3,col4,col5,col6,col7) values('".$value1."','".$value2."','".$value3."','".$value4."','".$value5."','".$value6."','".$value7."')";
mysqli_query($conn,$qry);
}}
 fclose($open);

py_txt.txt is something like this

9,5,6,7,8,9,1,0
4,6,7,8,9,1,2,1

how can i do that?

0 Answers0