[Solved] How can I update data in mySQL database?


I assume that you are wanting to update the “numbers” in your SQL table?

If so, you will need some sort of identifier to identify the rows which should be affected. So, if you want to set number=235443534 where the animal is equal to “Dog” then you will need to put that identifier in your text file. You may wanted to make the file colon seperated (;)?

Once you have got an identifer, you will need to read the file and loop through it.

<?php
$fileName = "FileNameHere.txt";
$fileToOpen = fopen($fileName,"r") or die("Error opening file :'(");
$readFile = fread($fileToOpen,filesize($fileName));

foreach($readFile as $fileLine){
 $item = split(";",$fileLine); //this will return an array {dog,34423}
 $sql = "UPDATE `animals' SET number="".$item[1]."" WHERE animal="".$item[0].""";
 //Run your SQL and any cool code here...
}

fclose($fileToOpen);
?>

For more about SQL update and working with files have a look at W3Schools tutorials. They’re really good! 😀

3

solved How can I update data in mySQL database?