Hi I would like to know how can I skip certain colums/rows from a csv. I have a form that uploads a cvs to MySQL and works fine, I also know how to skip the first line of the csv, but the format of the file I need to upload seems pretty hard for me. This is my code:
<body>
<div class="container">
[enter image description here][1]<?php
if(isset($_POST['uploadBtn'])){
$fileName=$_FILES['myFile']['name'];
$fileTmpName=$_FILES['myFile']['tmp_name'];
//FILE PATH
$fileExtension=pathinfo($fileName,PATHINFO_EXTENSION);
//ALLOWED FILE TYPES
$allowedType = array('csv');
if(!in_array($fileExtension,$allowedType)){?>
<div class="alert alert-danger">
INVALID FILE
</div>
<?php }else{
$handle = fopen($fileTmpName, 'r');
fgetcsv($handle);///////////////// SKIP FIRST ROW
while (($myData = fgetcsv($handle,1000,','))!== FALSE){
$name = $myData[0];
$email = $myData[1];
$query = "INSERT INTO databse.excel_table (name,email)
VALUES ('".$name."','".$email."')";
$run = mysql_query($query);
}
if(!$run){
die("error in uploading file".mysql_error());
}else{ ?>
<div class="alert alert-success">
SUCCESS
</div>
<?php }
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<h3 class="text-center">
RESULTS
</h3></hr>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="file" name="myFile" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="submit" name ="uploadBtn" class="btn btn-info">
</div>
</div>
</div>
</form>
</div>
</body>
</html>
Thanks in advance. example of csv
if-thenclause?