upload
Denne index.php som er et upload til mysql den fejler i linje 14 i localhost men ikke online. Men online uploader den og smider både navn og email i den samme tabelitem1 er navn på linje 13 og item2 er email på linje 14
leif Albert postmaster@web.dk
de er i en csv fil
sådan ser localhost ud
Notice: Undefined offset: 1 in /Applications/MAMP/htdocs/Update_csv/index.php on line 14
<?php
$connect = mysqli_connect("localhost", "root", "root", "test_db");
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))
{
$item1 = mysqli_real_escape_string($connect, $data[0]);
$item2 = mysqli_real_escape_string($connect, $data[1]);
$query = "INSERT into excel(excel_name, excel_email) values('$item1','$item2')";
mysqli_query($connect, $query);
}
fclose($handle);
echo "<script>alert('Import done');</script>";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
</head>
<body>
<h3 align="center">How to Import Data from CSV File to Mysql using PHP</h3><br />
<form method="post" enctype="multipart/form-data">
<div align="center">
<label>Select CSV File:</label>
<input type="file" name="file" />
<br />
<input type="submit" name="submit" value="Import" class="btn btn-info" />
</div>
</form>
</body>
</html>