Jump to content

Error when importing csv file onto ftp server database


candice

Recommended Posts

Hi all, i have a csv fiile that has to be imported to a ftp server database. The code works when i am trying out the application on localhost, and the data in the file is successfully uploaded and sent in the database. however, this becomes an issue on when my files are launched on the ftp server.

 

I get this following error:

SQL ERROR:Access denied for user 'istaff'@'%' (using password: YES)

 

does anyone know what this means?

 

I'm attaching my code here, perhaps it might help. Thanks!!

 

<?php 
session_start();
echo $name;
ob_start();
?>

<?php require_once('staffSql.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Staff Signage: Web Portal</title>

<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="4"><?php include("./include/headerAdmin.php"); ?></td>
  </tr>
  <tr>
    <td colspan="4" bgcolor="#FFFFFF" height="6"></td>
  </tr>
  <tr>
    <td width="5" valign="top" bgcolor="#FFFFFF"> </td>
    <td width="175" align="center" valign="top" bgcolor="#FFFFFF"><?php include("./include/leftBar.php");?></td>
    <td width="7" bgcolor="#FFFFFF"> </td>
    <td width="614" valign="top" bgcolor="#FFFFFF"><table width="605" border="0" align="center" cellspacing="0">
      <tr>
        <td height="20" valign="middle" bgcolor="#437AB6"><span class="contentHeader">   Import Staff Timetable</span></td>
      </tr>
      <tr>      </tr>
      <tr>
        <td valign="top" bgcolor = "#FAFAF5"><form action="import2.php" method="post" enctype="multipart/form-data">
            <div align="center">
              <p align="left" class="contentText">Here, you can upload a new staff timetable into the database with each new semester. The old timetable would be replaced once the new one has been uploaded into the database. Please note that <strong>ONLY CSV </strong>files are allowed to be uploaded to the database. There is however, no file size limit.</p>
              
              <p align="center" class="contentText">File Path
                <input type="file" name="fileupload" id="fileupload" />
              </p>
              <p align="center">
                <input type="submit" name="upload" id="upload" value="Submit" />
              </p>
              <p align="center">
              
              <?php 

//FUNCTION TO GET THE EXTENSION OF THE FILE THAT IS BEING UPLOADED
function getExtension($str) {
$i = strrpos($str,".");         
if (!$i) { 
return ""; 
}         
$l = strlen($str) - $i;         
$ext = substr($str,$i+1,$l);         
return $ext; 
}


//UPLOADING FILE
if(isset($_POST['upload']))
{

$filetype = $_FILES['fileupload']['type'];

if(empty($filetype)){

	echo'<font color="red"><span class = "contentText"><b>Please click on the browse button to locate your file</b></span></font>';
	//echo "<script language=\"JavaScript\">";
	//echo "alert('Please click on the browse button to locate your file');";
}

if($filetype){

	$csvfile = stripslashes($_FILES['fileupload']['name']); 	

	$extension = getExtension($csvfile); 	

	$extension = strtolower($extension);

	//echo $extension;

	if (($extension != "csv") && ($extension != "CSV")){	

		echo'<font color="red"><span class = "contentText"><b>Invalid file type. Please upload only .csv files</b></span></font>';
		/*echo "<script language=\"JavaScript\">";
		echo "alert('Invalid file type. Please upload only .csv files');";
		echo "</script>"; 
		*/
	}
	else {

		$uploaddir = 'images/uploaded/';

		$uploadfile = $uploaddir . basename($_FILES['fileupload']['name']);

		if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) {

			echo "<span class='contentText'>File is valid, and was successfully uploaded.\n</span>";
			echo "<span class = 'contentText'>Cick <a href ='admin_timetable.php'><b>here</b></a> to view the timetable that you have just uploaded";


		} 

		//TRUNCATE THE FILE BEFORE INSERTING IT INTO THE DATABASE
		mysql_select_db($dbname, $root);

		//mysql_select_db($dbname, $root); 

		mysql_query("TRUNCATE TABLE timetable") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

		//LOAD DATA FILE INTO DATABASE
		$query = 'LOAD DATA INFILE "'.$uploadfile.'" REPLACE
		INTO TABLE timetable 
		FIELDS TERMINATED BY ","
		OPTIONALLY ENCLOSED BY """"
		LINES TERMINATED BY "\r\n"';

		mysql_query($query, $root) or die('SQL ERROR:'.mysql_error()); //Insert in the new values into the database


	}



}


}

?></p>
            </div>
        </form></td>
      </tr>
    </table>    
    <p><br />
    </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p>           </p></td>
  </tr>
  <tr>
    <td colspan="4"><?php include("include/footer.php") ?></td>
  </tr>
</table>
</body>

</html>
<?php ob_flush(); ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.