cluce Posted June 16, 2008 Share Posted June 16, 2008 I have an issue with uploading and keeping the same data in my excel spreadsheet when I convert it to a csv file. First, I tried to insert the excel spreadsheet into the database using the following code: <?php $counter = 1; //initialize counter include'db.php'; include'salt.php'; $handle = fopen("triaport.xls","r"); while(($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $company = $data[0]; $division_number = $data[1]; $username = $data[2]; $password = $data[3]; $f_name = $data[4]; $l_name = $data[5]; $email = $data[6]; $priv = $data[7]; $sql = "INSERT INTO employees (deleted for security reasons) VALUES (')"; mysqli_query($mysqli, $sql); $counter++; echo 'SQL='.$sql.'<br/>'; } ?> which works fine with a csv file. But the problem is two of the columns in my table require leading zeros and csv file removes the leading zeros. I tried to use an excel spreadsheet but it does not work with my loop which inserts Null values in my table. I have about 500 records so manually adding leading 0's in the csv file would be tedious. A csv file removes all formatting which changes the actual data that I need to insert in the databse. Does anybody know any other method I can use to insert a file into the MYSQL database? Or know how to use another type of file besides a csv file that would work? Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted June 16, 2008 Share Posted June 16, 2008 Try formatting the column as text within Excel... I had to do the same thing once for the same reason and that did the trick. Quote Link to comment Share on other sites More sharing options...
cluce Posted June 16, 2008 Author Share Posted June 16, 2008 thats what I was thinking. I am trying that out right now. 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.