Created
January 10, 2021 02:35
-
-
Save JasvinderSingh1/8f8b936e9395ff07fa21a56237f85df8 to your computer and use it in GitHub Desktop.
php import from excell, csv to database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST["submit"])) | |
{ | |
$url='localhost'; | |
$username='root'; | |
$password=''; | |
//$conn=mysqli_connect($url,$username,$password,"location"); | |
$conn=mysqli_connect("localhost", "euodias_dev1", "euodias_dev1@321!", "euodias_redrope"); | |
if(!$conn){ | |
die('Could not Connect My Sql:' .mysqli_error()); | |
} | |
$file = $_FILES['file']['tmp_name']; | |
$handle = fopen($file, "r"); | |
$c = 0; | |
while(($filesop = fgetcsv($handle, 1000, ",")) !== false) | |
{ | |
$emails = $filesop[0]; | |
$sql = "insert into users_2(fname,lname) values ('$emails')"; | |
$stmt = mysqli_prepare($conn,$sql); | |
mysqli_stmt_execute($stmt); | |
$c = $c + 1; | |
} | |
if($sql){ | |
echo "sucess"; | |
} | |
else | |
{ | |
echo "Sorry! Unable to impo."; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<form enctype="multipart/form-data" method="post" role="form"> | |
<div class="form-group"> | |
<label for="exampleInputFile">File Upload</label> | |
<input type="file" name="file" id="file" size="150"> | |
<p class="help-block">Only Excel/CSV File Import.</p> | |
</div> | |
<button type="submit" class="btn btn-default" name="submit" value="submit">Upload</button> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment