I have written this code (plus the config.php file - which works in another application)
but am obviously doing something wrong in the following code
(which I submit without the usual PHP open and close symbols of < etc and >)
<?php
include "config.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$datetransferred=$_POST['datetransferred'];
$known_as=$_POST['known_as'];
$email=$_POST['email'];
$dob=$_POST['dob'];
$filename="/markreada.csv"; // this comes from another file but unsure it works
// $handle = fopen("$filename", "r"); // problems so fix a name and try that
$handle = fopen("markreada.csv", "r"); //maybe this might work
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT INTO `raw_hotmail` (`datetransferred` , `known_as` , `email` , `dob`)
VALUES('$datetransferred' , '$known_as' , '$email' , '$dob')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done1";
}
else
{
print "Import done2";
}
echo "I am here processing I hope";
?>
- <?php
- include "config.php";
- if(isset($_POST['submit']))
- {
- $filename=$_POST['filename'];
-
- $datetransferred=$_POST['datetransferred'];
- $known_as=$_POST['known_as'];
- $email=$_POST['email'];
- $dob=$_POST['dob'];
-
- $filename="/markreada.csv"; // this comes from another file but unsure it works
-
- // $handle = fopen("$filename", "r"); // problems so fix a name and try that
- $handle = fopen("markreada.csv", "r"); //maybe this might work
- while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
- {
- $import="INSERT INTO `raw_hotmail` (`datetransferred` , `known_as` , `email` , `dob`)
- VALUES('$datetransferred' , '$known_as' , '$email' , '$dob')";
- mysql_query($import) or die(mysql_error());
- }
- fclose($handle);
- print "Import done1";
- }
- else
- {
- print "Import done2";
- }
- echo "I am here processing I hope";
- ?>
PROBLEMS
1. The above code DOES OPEN the DataBase yet BLANK RECORDS ARE SAVED
2. Ideally I would like to be able to type in various file names and their locations
on my home computer (rather than fix a name) eg C:\temp\readthisfile.csv
3. should the slash be (a) \ (as xp at home) or (b) / as host is Linux server
(if some kind person might be able to solve - much appreciated)
Many thanks
Moderator Remark: You can use [php]...[/php] to wrap code blocks.