xclusivzik Posted November 25, 2014 Share Posted November 25, 2014 when i input this code it only uploads a single column into my database <html> <head> <title>MySQL file upload example</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="try2.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" name="submit"value="Upload file"> </form> <p> <a href="list_files.php">See all files</a> </p> </body> <?php $con=mysqli_connect("localhost","root","","book"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if(isset($_POST['submit'])) { $fname = $_FILES['uploaded_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['uploaded_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into data(name,Groups,phone_number) values('$data[0]','$data[1]','$data[2]')"; $result=mysqli_query($con,$sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> </html> Link to comment https://forums.phpfreaks.com/topic/292699-uploading-a-csv-file-into-mysql-database/ Share on other sites More sharing options...
mac_gyver Posted November 25, 2014 Share Posted November 25, 2014 which of your three columns is the only one that is getting a value and is that value the expected value or is it the complete line from the csv file? short-answer: we are not sitting there with you and when you state something like "it only uploads a single column into my database" we don't know what you saw, but knowing that information tells us where to look at to find the problem. so, it is always helpful to post some example input data you are using with your code, what result you are getting from that input data, what exactly is wrong with that result, and what result you expected to get. Link to comment https://forums.phpfreaks.com/topic/292699-uploading-a-csv-file-into-mysql-database/#findComment-1497617 Share on other sites More sharing options...
xclusivzik Posted November 25, 2014 Author Share Posted November 25, 2014 want it to create a new table for the data when uploaded Link to comment https://forums.phpfreaks.com/topic/292699-uploading-a-csv-file-into-mysql-database/#findComment-1497622 Share on other sites More sharing options...
mac_gyver Posted November 25, 2014 Share Posted November 25, 2014 you last reply is not what you stated at the start of this thread and it would appear your last reply is what your other current thread is about. please don't start multiple threads for the same problem and we can only help you when you clearly state what problem you are having with your code. Link to comment https://forums.phpfreaks.com/topic/292699-uploading-a-csv-file-into-mysql-database/#findComment-1497624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.