내 관리 영역에 CSV 파일을 가져올 때 데이터베이스에 파일을 추가하고 싶습니다. import.php
에 대한 나의 PHP 코드는 다음과 같습니다PHP를 통해 MYSQL로 CSV 가져 오기
<?php
include_once('../include/connection.php');
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO mobi(promo_title, promo_content, promo_image, promo_link, promo_cat, promo_name) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."',
'".addslashes($data[5])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//redirect
header('Location: import.php?success=1'); die;
}
?>
<!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=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>
<body>
<?php if (!empty($_GET[success])) { echo "<b>Your file has been imported.</b><br><br>"; } //generic success notice ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file: <br />
<input name="csv" type="file" id="csv" />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>
코드가 올바르게 표시하지만 난 내 테스트 파일을 선택하고 공격 할 때 이러한 문제를, 내가 공격하고 제출
Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: Access denied for user 'root'@'localhost' (using password: NO) in admin/import.php on line 23
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in admin/import.php on line 23
Warning: Cannot modify header information - headers already sent by (output started at admin/import.php:1) in admin/import.php on line 29
사람이 이유를 볼 수 있을까요?
내 connection.php 코드는 이것이다 :
<?php
try {
$pdo = new PDO('mysql:host=localhost;dbname=*********', '*********', '*********');
}catch (PDOException $e){
exit('Database Error.');
}
?>
주의하시기 바랍니다 등은 add.php, delete.php, edit.php 등등과 같은 연결 같은 include_once 문 모든 일에 내 다른 페이지. PHP
그래서 내 데이터베이스 연결에는 아무 것도 없습니다.
감사합니다.
데이터베이스가 구축 교정하려면'connection.php'을 확인합니다. – hallaji
안녕하세요. 내 연결 인스턴트 메신저를 사용하여 : try {$ pdo = new PDO 위의 코드에 반영해야합니까? – kevstarlive
당신의 데이터베이스는'password'를 가지고 있고 당신은 그것을 비워 두었습니다. – hallaji