I am unable to get my text file data.txt to read correctly into my database.
This is what my text file looks like
9889483782,6068378394,6069437364... and so on for like 50 numbers
I have to get each of the comma seperated values to show up in the database, id like them to be placed in their own respective row in my table numdata where the values will be inserted in the field, Numb.
My problem is that im not getting any errors? but my code produces no results. What do i do to fix this?
Also please try to elaborate and use code examples, i learn better by seeing it work as well as understaing how it works. Thank You.
Another quick note, the data in the txt file has nothing else in it, no spaces or anything just comma seperated vlaues.
<?php
require ('dbconnect.php'); // connect to database
// initial database stuff
$file = "data.txt";
$file_handle = fopen($file, "r");
fclose($file_handle);
while (($data = fgetcsv($file_handle, 1000, ",")) !== FALSE)
{
$i = 1;
foreach($file as $row)
{
$data = explode(',',$row);
$query .= $i < $count ? ',':'';
$i++;
}
$query="INSERT into Numbers(Numb) values('$data')";
mysql_query("TRUNCATE TABLE Numbers") or die("MySQL Error: " . mysql_error()); //Delete the existing rows
mysql_query($query) or die(mysql_error());
}
echo "Done!";
?>