when i click upload button, it takes long to load wthout csv, but when i upload csv it dispays csv pocessed..but there is no data uploaded...what could be the wrong with my code?...please assist me

   <form enctype="multipart/form-data" method="POST" action="" > 
   <input type="file" name="file" /><br />
   <input type="submit" value="upload csv" name="submit"/>
   </form>

     <?php
         $connection = mysql_connect("localhost","root","")
         or die ("Couldn't connect to server");
         $db = mysql_select_db("syrecuse1", $connection)
         or die ("Couldn't select database");

        if(isset($_POST['submit']))
        {
        $file = $_FILES['file']['tmp_name'];
        $handle = fopen($file,"r");

        $processed = false;
        while(($fileop = fgetcsv($handle,1000,",")) !== FALSE)
        {
        $firstname = $fileop[0];
        $lastname = $fileop[1];
        $email = $fileop[2];

        $sql = mysql_query("INSERT INTO test (first_name, last_name, email)      values('$firstname', '$lastname', '$email')");

        $processed = true;
    }

    if($processed)
    {
        echo "CSV was processed.";
    }
    else
       {
        echo "CSV was not processed.";
       }
    }
    else
    {
    echo "Submission was not found.";
    }

?>

any error messages?

Do you use php in production or dev mode try this

error_reporting(E_ERROR | E_WARNING | E_PARSE);

and see what you get.
One more idea validate your data and use pdo to be safe.
Are you trying to upload a file to a directory and to the database too?

sory for my delayance itravelled now i am back

I gat no error messege
i use php in development
i am uuploading file into the database

Ok first thing's first don't use else else in php and in other programming languages there is no double else.
But there is a else if statement.

Can you show your database?
(Use the describe command to print out your database)

What do you use?(Lamp xamp wamp ,mac ,Windows,linux)

Did you verify if the file exist in that location?

Did you follow a tutorial or made this example yourself?

If you provide those information than i might be able to assit you further.

Have a nice day

Ok first thing's first don't use else else in php and in other programming languages there is no double else.

I think you missed a bracket ;) His construct is valid, although hard to read because of the lack of indentation.

i think, u can use javascript.., it's very helpful..

i am very green in java ..can you code with java?

i finally null it and it works perfect............

<?php
 $connection = mysql_connect("localhost","root","")
 or die ("Couldn't connect to server");
 $db = mysql_select_db("DB", $connection)
 or die ("Couldn't select database");
 if(isset($_POST['submit']))
{

$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,"r");
if (($handle = fopen($file, "r")) !== FALSE) {

while ($fileop = fgetcsv($handle,1000,",","'"))
{
$a = $fileop[0];
$b = $fileop[1];
$c = $fileop[2];
$d = $fileop[3];
$e = $fileop[4];
$f = $fileop[5];
$g = $fileop[6];
$h = $fileop[7];
$i = $fileop[8];

$sql = mysql_query("INSERT syracuseone (TERRITORY,  FIRST_NAME, LAST_NAME, TYPE, DESCRIPTION, START_DATE, END_DATE, DURATION, STATUS)

values('$a', '$b', '$c', '$d', '$e', '$f', '$g', '$h', '$i')");

}
}
}

?>

<?php
if (isset($_POST) && count($_POST) > 0) {
  header("Location:       http://www.example.com/"); /* Redirect browser */
  exit();
}

?>
<form enctype="multipart/form-data" method="POST" action="" >
CSV<input type="file" name="file" />
<input type="submit" value="submit" name="submit"/>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.