Answer the question
In order to leave comments, you need to log in
How to change the values in the database from a .csv file in php?
Good afternoon, please tell me how to change the values in the database from the csv file?
We have file.csv
A unique field in the database - login I figured out
how to add data from csv, using the code below.
But I didn’t understand how to replace the data, if, for example, passwords change
<?php
header('Content-type: text/html; charset=utf-8');
$mysqli = new mysqli('localhost', 'bd_login', 'bd_password', 'bd_name');
$logPswd = fopen('file.csv', 'r');
while( !feof($logPswd) ) {
$mass = fgetcsv($logPswd, 512, ',' );
$j = count($mass);
if($j > 1){
$mysqli->query("INSERT INTO `users` ( `id`, `login`, `password` ) VALUES ( '{$mass[0]}', '{$mass[1]}', '{$mass[2]}' ) ");
}
}
fclose($logPswd);
$mysqli-close();
?>
Answer the question
In order to leave comments, you need to log in
We must learn to ask the right questions.
Now it sounds like this: How to change the values in the database from a .csv file in php?
And should so: How to update the data in a DB
After all csv has no relation to a problem, you already successfully read the data from a csv file.
Here is the answer to your question:
https://www.w3schools.com/mysql/mysql_update.asp
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question