Jump to content

[SOLVED] PHP Multiple Languages


SkyRanger

Recommended Posts

I am trying to create a site with multiple languages.  I am having a problem changing from one language to another.

 

Here is what I have so far

 

index page:

include "./includes/get_language.php";

include "./includes/languages/".$path."/main.lang.php";
include "./includes/languages/".$path."/sub/index.lang.php";
?>

<a href='index.php?lid=1'>English</a>
<a href='index.php?lid=2'>French</a>


<?php
echo _TITLEOFPAGE;
echo "<br><br>";
echo _DESCOFPAGE;

 

get_language.php:

$connection=mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());
        mysql_select_db ("$dbname");

$sql1 = mysql_query("SELECT lang from variables") or die(mysql_error());
while($row1 = mysql_fetch_array($sql1))
  {
  $newlang = $row1['lang'];
  }

if (empty($_SESSION['language']['lid'])) {
$_SESSION['language']['lid'] = $newlang;
}

$cnn = mysql_connect ("$dblocation", "$dbusername", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error());

if (!$cnn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("$dbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

//your query (if it's okay; check it with echo command - echo $sql to see if it's good)

$sql = "SELECT * FROM languages WHERE lid = " . $_SESSION['language']['lid'];

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {

$path = $row['lpath'];
}

mysql_free_result($result);

 

I can get the primary language to read but I cannot get the language to change with I click on the link.  Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/146751-solved-php-multiple-languages/
Share on other sites

if (empty($_SESSION['language']['lid'])) {
$_SESSION['language']['lid'] = $newlang;
}

 

Doesn't the above code only add a value to the session variable if it is empty? If this is the case, when you first try and set the primary language, the variable is empty and is therefore added to the session variable. Now, when you try to change the language, the session variable is not empty and is therefore not assigned it's new value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.