Peg Posted April 10, 2014 Share Posted April 10, 2014 I have a bit of code that I have used for years to upload to upoad data from a csv file to a database. I built a website on a Godaddy Server, then after the site was tested and approved, the site was moved another server. I do not have any access to the new server and the code does not work on the new server. I'm sure that it has to do with security issues on the server? The first part of the code that truncates the table did work. So I know that the connection to the database is correct. Here is the code: <?php$sql3 = "TRUNCATE TABLE this_table";$result3 = mysql_query($sql3,$db) or die(mysql_error(). "<br />SQL: $sql3");ini_set('auto_detect_line_endings',true);if (($handle = fopen($csvfile, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $sql = "INSERT INTO this_table (first_name,last_name,title,field_1,field_2,field_3,field_4) VALUES("; $search = array(" & ",'"',"'",","); $replace = array(" & ",'"', '’',","); for ($c=0; $c < $num; $c++) { $sql .= "'". str_replace($search,$replace,$data[$c]) . "',"; } $sql = substr($sql, 0, -1) .")"; $result = mysql_query($sql,$db) or die(mysql_error(). "<br />SQL: $sql"); } fclose($handle);}ini_set('auto_detect_line_endings',false);?> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 10, 2014 Share Posted April 10, 2014 the code does not work sorry, but that's useless information. by not telling us what it does do (even telling us it resulted in a blank page is a clue that helps narrow down the problem), we cannot help you with the many possible things that could go wrong with any piece of code. the only apparent issue with the posted code is it doesn't have any logic in it to tell you if the fopen() statement has failed. Quote Link to comment Share on other sites More sharing options...
Peg Posted April 10, 2014 Author Share Posted April 10, 2014 Does anyone know if there is a difference between the way this code would work on a windows server and how it works on a Lynx. The code worked great on the Godaddy lynx server, but does not work on the current server that is a windows server. Quote Link to comment Share on other sites More sharing options...
Peg Posted April 10, 2014 Author Share Posted April 10, 2014 The page does not go blank. The code does not produce any php errors when the csv is uploaded to the site. I say this because the page loads completely. Does that help any? Sorry, this is difficult for me because I do not have access to the server. I can not ftp into the site. Quote Link to comment Share on other sites More sharing options...
Peg Posted April 10, 2014 Author Share Posted April 10, 2014 Maybe it is this code that is not working on their server. I might assume that since it is a server with security on it, that the temporary files are accessed differently. Does that make sense? $csvfile = $_FILES['userfile']['tmp_name'];$size = $_FILES['userfile']['size']; Quote Link to comment Share on other sites More sharing options...
boompa Posted April 10, 2014 Share Posted April 10, 2014 Well, you could test for the existence of the csv file before you try to open it to see if that's the issue. As mac_gyver intimated, you could also output an error if the fopen fails. That might narrow things down for you. Quote Link to comment Share on other sites More sharing options...
Peg Posted April 10, 2014 Author Share Posted April 10, 2014 Yes, that makes sence to me. I do not however have ftp access to the site. I will have to wait until Tuesday when my clients tech is in. Then have him upload that code to the server. This makes it difficult to trouble shoot! Thank You! Quote Link to comment Share on other sites More sharing options...
Ken_GoDaddy Posted May 3, 2014 Share Posted May 3, 2014 @Peg, I'm with GoDaddy and came across your post. Are you still running into the issues you were experiencing with your code? Additionally, you mentioned the site was built on a Linux Server with GoDaddy, is the Windows Server also with us? If you still are running into issues feel free to reply or send me a private message. Quote Link to comment Share on other sites More sharing options...
Peg Posted May 20, 2014 Author Share Posted May 20, 2014 Thank you Ken. No the Windows server is not with GoDaddy. The server is "on site" in my clients building. That is actually all I know, besides the fact that there is protected information on the server. 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.