SkyRanger Posted February 24, 2009 Share Posted February 24, 2009 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 More sharing options...
br0ken Posted February 24, 2009 Share Posted February 24, 2009 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. Link to comment https://forums.phpfreaks.com/topic/146751-solved-php-multiple-languages/#findComment-770478 Share on other sites More sharing options...
SkyRanger Posted February 24, 2009 Author Share Posted February 24, 2009 Yeah, but not sure how to fix that, 2 days of fighting with code is what brought me here. Link to comment https://forums.phpfreaks.com/topic/146751-solved-php-multiple-languages/#findComment-770496 Share on other sites More sharing options...
br0ken Posted February 24, 2009 Share Posted February 24, 2009 $_SESSION['language']['lid'] = $newlang; That will remove the check. Now every time you attempt to add a value, it will be added. Link to comment https://forums.phpfreaks.com/topic/146751-solved-php-multiple-languages/#findComment-770564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.