how to upload excel file and its data to be stored into phpmyadmin

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sanitprof
    New Member
    • Dec 2013
    • 4

    how to upload excel file and its data to be stored into phpmyadmin

    hi there,

    how to upload an excel file and its data to be stored into database(phpmya dmin) using php.

    thanks.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    This cannot be done because phpmyadmin is not a database.

    According to wikipedia:
    "phpMyAdmin is a free and open source tool written in PHP intended to handle the administration of MySQL with the use of a web browser."

    But you probably do mean a mysql database ;-)

    Than the question is how should the data in your excel file be 'converted' to this database?

    Where/how do you store your tablenames/columnnames/data?

    But maybe this can help you:
    MySQL for Excel

    Comment

    • Mukesh9023
      New Member
      • Nov 2013
      • 11

      #3
      yes it is possible.use Spreadsheet_Exc el_Reader,searc h in google how we upload excel file in php using excel_reader_se arch.

      Comment

      • Sanitprof
        New Member
        • Dec 2013
        • 4

        #4
        yea phpmyadmin is a server tool to access and manage the db's on mysql servers. thanks for correcting me:)

        in that link, by manually importing/exporting of excel data into mysql., such things has given.

        what i required is that at by run time excel file has to uploaded and stored into database. check out my attachment, the sample format that to be stored.

        to Mukesh : i've seen something about php_excel_reade r, its very much useful for reading and writing xls files from php. but while uploading, how can i convert my excel datas into db?

        thanks.
        Attached Files

        Comment

        • Luuk
          Recognized Expert Top Contributor
          • Mar 2012
          • 1043

          #5
          If you want to read the data from your excel file, you should google for a script..... "php reading xlsx"

          There are lots of examples on the internet...
          Download, and inspect the code to find out how they do it...

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            Sanitprof
            You will need show us your work.
            Please format your script using the [CODE/] button.

            We can help you fine tune code, even locate and correct errors provided the basic trouble shooting has been done; however, we normally do not write completed code nor provide finished project (the exceptions usually being after a lot work or something that is really obscure).

            Comment

            • Sanitprof
              New Member
              • Dec 2013
              • 4

              #7
              Look out these sample codes Luuk and zmbd

              html code to set upload

              Code:
              <div id="mainbody">
                  <form method="post" action="e2.php" enctype="multipart/form-data">
                      <input type="file" name="file" /> <br />
                      <input type="submit" name="submit" value="Submit" />
                  <form />
              
              </div>
              php script to store uploaded excel data

              Code:
              $conn = mysql_connect("localhost","root","") 
              if (!$conn) 
              {
                die('Not connected : ' . mysql_error());
              }
              $db_selected=mysql_select_db("dbname",$conn);
              if (!$db_selected) 
              {
                die ('Can't use db : ' . mysql_error());
              }
              
              if(isset($_POST['submit']))
              {
                  $file = $_FILES['file']['tmp_name'];
              
                      $handle = fopen($file,"r+");
              	print_r(fgetcsv($file));
                      while(($fileop = fgetcsv($handle,1000, ",")) !==false)
                  {
              
                      $Name = $fileop[0];
                      $Surname = $fileop[1];
                      $Address = $fileop[2];
                      $e-mail = $fileop[3];
              
                      $sql = mysql_query("INSERT INTO csv (Name,Surname,Address,e-mail) VALUES('$Name','$Surname','$Address','$e-mail')");
              	}	
                      if($sql)
                      {
                          echo 'data uploaded succesfuly';
                      }
                  
              }
              everything seems correct? but not working. help this out.
              thanks.

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                OK, what are the issues with the code you posted?
                Receiving an error - which and what line?
                Only working partially, then what is and is not the code doing for you?
                Help us to help you...

                As Luuk pointed out, if we wanted sample code, there's tons of it online available for a simple search; however, this isn't our project, it yours, and we're willing to help you with specific issue(s) just not do the work for you.

                Comment

                • Sanitprof
                  New Member
                  • Dec 2013
                  • 4

                  #9
                  thanks for ur willingness. i really appreciate u.

                  file is getting uploaded but not storing into db. so at line 26 i added if..else to check whether query is executing or not, then it returns 'Query was empty'.

                  i was on search, then i found these code, it solved my problem.


                  thanks.

                  Comment

                  • Luuk
                    Recognized Expert Top Contributor
                    • Mar 2012
                    • 1043

                    #10
                    hmm, it seems to be difficult to post some code, and give a proper linenumber where things stop working.

                    When asked some people start Googling, and change their original problem from:
                    "how to upload excel file and its data to be stored into phpmyadmin"
                    to:
                    "Upload CSV and Insert into Database Using PHP/MYSQL"

                    But i'm glad your problem is solved.... ;)

                    Comment

                    Working...