tags:

views:

158

answers:

1

Hi,

 i am having an form for uploading an excel file like

   <form enctype="multipart/form-data" action="http://localhost/joomla/Joomla_1.5.7/index.php?option=com_jumi&amp;fileid=7" method="POST">
     Please choose a file: <input name="file" type="file" id="file" /><br />
     <input type="submit" value="Upload" />
    </form> 

And in the FIle http://localhost/joomla/Joomla_1.5.7/index.php?option=com_jumi&amp;fileid=7

i have retrived the uploaded file contents by



  <?php echo "Name". $_FILES['file']['name'] . "<br />";

   echo "Type: " . $_FILES["file"]["type"] . "<br />";
   echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
   echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br />";
   $string = file_get_contents( $_FILES["file"]["tmp_name"] );

        foreach ( explode( "\n", $string ) as $userString )

    {

        $userString = trim( $userString );
                    echo $userString;$array = explode( ';', $userString );



          $userdata = array
       ( 'cf_id'=>trim( $array[0] ),
      'text_0'=>trim( $array[1] ),
        'text_1'=>trim( $array[2] ),
         'text_2'=>trim( $array[3] ),
       'text_3'=>trim($array[4]),
       'text_6'=>trim($array[5]),
        'text_7'=>trim($array[6]),
   'text_9'=>trim($array[7]),
      'text_12'=>trim($array[8]));



           global $db; $db=& JFactory::getDBO();


          $query =  'INSERT INTO #__chronoforms_UploadAuthor VALUES ("'.$userdata['cf_id'].'","'.$userdata['text_0'].'","'.$userdata['text_1'].'","'.$userdata['text_2'].'","'.$userdata['text_3'].'","'.$userdata['text_6'].'","'.$userdata['text_7'].'","'.$userdata['text_9'].'")';

          $db->Execute($query);

          echo "<br>";

            }

i am trying to insert the contents into the table #__chronoforms_UploadAuthor in Joomla database . it doent shows any error but it is not inserted into the database..

Please help me.. Y the contents are not inserted into the database...And how to make it inserted into the database..

EDIT:

i have echoed the Query and its shown as INSERT INTO jos_chronoforms_UploadAuthor VALUES ("1",""Concept-paper-WSN_02.pdf"",""Wi-SenseScape, wireless sensor networks"",""TCS Innovation Labs, Bangalore"",""Internal"",""Wi-SenseScape"",""Harish Reddy, Vishnu, Deepika, T.Chakravarty and Balamuralidhar"",""2008"","","") .. since there are 2 double quotes , it is not inserted into the database .. Pls tel me how to solve this..

so that the QUery should be like INSERT INTO jos_chronoforms_UploadAuthor VALUES ("1","Concept-paper-WSN_02.pdf","Wi-SenseScape, wireless sensor networks","TCS Innovation Labs, Bangalore"","Internal"",""Wi-SenseScap","Harish Reddy, Vishnu, Deepika, T.Chakravarty and Balamuralidhar","2008","","")

+2  A: 

First try to find out the sql query:

echo $query;

now copy that query and execute in mysql client like phpmyadmin or sqlyog. If records gets inserted, then you have error somewhere else in your code but if you see any error you should try to solve that error in your query.

Edit:

You need to use addslashes or mysql_real_escape_string function before your values that you insert into your database:

$query =  'INSERT INTO #__chronoforms_UploadAuthor VALUES ("'.addslashes($userdata['cf_id']).'","'.addslashes($userdata['text_0'])............and so on
Sarfraz
i have echoed the Query and its shown as INSERT INTO jos_chronoforms_UploadAuthor VALUES ("1",""Conceer-WSN_02.pdf"",""Wi-SenseScape, wireless sensor networks"",""Labs, Bangalore"",""Internal"",""Wi-SenseScape"",""Harish, Vishnu, Deepika, T.Chakravarty and Balamuralidhar"",""2008"","","") .. since there are 2 double quotes , it is not inserted into the database .. Pls tel me how to solve this
Aruna
use addslashes or mysql_real_escape_string function before your values that you want to insert. See my updated answser.
Sarfraz