I'm making a table with translation:
English | Italian | French
help | ayuto | amo
and am creating a functionality to add new language (Russian). I have it all set up but the import doesn't work correctly. It imports the values under already existing fields. So it doesn't add them directly under the newly added language. Looks like this:
English | Italian | French | Russian(added)
help | ayuto | amo |
| | | помощь(imported)
| | | извините(imported)
I need that to start it from the top like this:
English | Italian | French | Russian(added)
help | ayuto | amo | помощь(imported)
| | | извините(imported)
Here is the code:
if (isset($_POST['submit'])){
$lang_name = htmlspecialchars($_POST['lang_name'], ENT_QUOTES);
$str = strtolower($lang_name);
$lang_lawname = str_replace(' ', '_',$str);
$sql = "INSERT INTO translation_lang (languages) VALUES ('".$lang_name."')";
$sql2 = "ALTER TABLE translation ADD $lang_lawname VARCHAR( 255 ) DEFAULT ''";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
if (!mysqli_query($con,$sql2)) {
die('Error: ' . mysqli_error($con));
}
if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
//echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>";
//echo "<h2>Displaying contents:</h2>";
readfile($_FILES['filename']['tmp_name']);
//Import uploaded file to Database
$handle = fopen($_FILES['filename']['tmp_name'], "r");
do {
if ($data[0]) {
$import="INSERT into translation($lang_lawname) values('$data[0]')";
mysqli_query($con,$import) or die(mysqli_error());
}
}
while ($data = fgetcsv($handle,1000,",","'"));
}