I have a text file named attend.txt with following content:
tcs15b021
tcs15b022
tcs15b023
tcs15b011
and here is my php code to insert data into the table named Attendance with following attributes:
CourseId, Date, RollNo, Status where CourseId and Date comes from the html form, RollNo is taken from the attend.txt file and Status is a direct string('Present' or 'Absent').
code
if(isset($_POST['submit'])){
$handle = @fopen("attend.txt", "r");
$CourseId = $_POST[CourseId];
$Date = $_POST[Date];
while (!feof($handle)){
$buffer = fgets($handle, 4096);
echo $buffer.'<br>';
$query = "insert into Attendance(CourseId, Date, RollNo, Status) values('$CourseId','$Date', '$buffer', 'Present')";
$flag = mysqli_query($con, $query);
if($flag){
echo 'Successful!';
}
else{
echo 'failed!';
}
}
}
The problem with the code is that it inserts only one row i.e, it loops through the while loop but query is executed only once.
any kind of help will be greatly appreciated.