jackgoddy123 Posted January 10, 2014 Share Posted January 10, 2014 Hello experts, Is it possible to upload excel file to my php myadmin. I know that all the field name of my phpmyadmin database table and my excel sheet table field should be same. But i am not finding the appropriate solution of this topic. The importing of my excel file code i am not finding out. And m confused in this. Below is the code i tried out: <form action="up1.php"> <input type="file" name="txtFile" id="eskal" /></br> <input type="submit" name="update" value="Update Database" /> </b> </form> up1.php: <?php if(isset($_POST["Import"])) { $host="localhost"; // Host name. $db_user="root"; $db_password=""; $db='test'; // Database name. $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error()); mysql_select_db($db) or die (mysql_error()); echo $filename=$_FILES["file"]["tmp_name"]; //echo $ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,"."))); if($_FILES["file"]["size"] > 0) { $file = fopen($filename, "r"); while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE) { print_r($emapData); $sql = "INSERT into import(name,address,email,password) values('$emapData[0]','$emapData[1]')"; mysql_query($sql); } fclose($file); echo "CSV File has been successfully Imported"; } else echo "Invalid File:Please Upload CSV File"; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import CSV/Excel file</title> </head> <body> <form enctype="multipart/form-data" method="post"> <table border="1" width="40%" align="center"> <tr > <td colspan="2" align="center"><strong>Import CSV/Excel file</strong></td> </tr> <tr> <td align="center">CSV/Excel File:</td><td><input type="file" name="file" id="file"></td></tr> <tr > <td colspan="2" align="center"><input type="submit" name="Import" value="Import"></td> </tr> </table> </form> </body> </html> I had mistaken in my up1.php code i knw. So, if some one could help me with the code here. Any kind of help is appreciated. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/285266-upload-excel-file-to-php-myadmin/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.