xclusivzik Posted November 25, 2014 Share Posted November 25, 2014 (edited) 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> Edited November 25, 2014 by mac_gyver code tags around posted code please Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.