我想使用来自网站前端的CSV文件将数据插入phymyadmin表,该文件必须更新我表格中的所有记录。
此代码根本不起作用。请找出错误。
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$conn = mysql_connect($servername, $username , $password );
if(! $conn ) {
die('Could not Find Some Error Occured: ' . mysql_error());
}
if(isset($_POST["submit"]))
{
if($_FILES['file']['name'])
{
$filename = explode(".", $_FILES['file']['name']);
if($filename[1] == 'csv')
{
$handle = fopen($_FILES['file']['tmp_name'], "r");
while($data = fgetcsv($handle))
{
$uname = mysqli_real_escape_string($connect, $data[0]);
$pass = mysqli_real_escape_string($connect, $data[1]);
mysql_select_db('desiresq_record');
$query = "INSERT into login (username, password)
VALUES ('$uname','$pass')";
mysqli_query($connect, $query);
}
fclose($handle);
echo "<script>alert('Import done');</script>";
}
}
}
?>
答案 0 :(得分:0)