PHP / jQuery based school project
<p>I'm developing a parents evening booking system as part of my A level programming project, but I've just gotten stuck. 
I'll try explain the project the best I can in this post, so I can give you guys a clear picture of what the application does.</p>

<p><strong>So far:</strong>
I have created a sort of language selector function with php, which gets the users language selection before logging in based upon a cookie. Here's the code for the script (Yes, very messy right now, but i'll fix it later on):</p>

<pre><code>function check_language() { 

//directory name for the custom defined languages.
$dir = 'languages'; 

//set a default language
$default = 'english';

//make sure that we have a language selected...
if (!isset($_COOKIE["lang"])){ 
    //if there is no cookie set, set one.
    setcookie("lang", "english", time()+3600*24*365);
}else{ 
    $lang = ($_COOKIE["lang"]); 
} 

//build the path string.
$path = $dir."/".$lang.".php";


if (file_exists($path)) {
    //return the selected language pack directory.
    return $path;
}else{
    //protect the server, by returning the default language path...
    return $dir."/".$default.".php";
}

} 
</code></pre>

<p>Whenever I want my PHP script to access language files, I call the function I have created and then include the language file on the page like so:</p>

<pre><code>$lang = check_language();
include_once($lang); 
</code></pre>

<p>english.php file...</p>

<pre><code>$txt['languagename'] = "English";

//text for the index page...
$txt['titletext'] = 'Parents evening booking system'; 
$txt['welcometext1'] = 'Welcome to the parents evening booking system for '; 
</code></pre>

<p>welsh.php file...</p>

<pre><code>$txt['languagename'] = "Cymraeg";

//text am y tudalen index...
$txt['titletext'] = 'System bwcio noson rhieni'; 
$txt['welcometext1'] = 'Croeso i system bwcio noson rhieni '; 
</code></pre>

<p>So for example, if the users cookie contains 'welsh', the file welsh.php would be included, and I would have access to an associative array ($txt), with the supplied translations.
That part of my script works perfectly so far.</p>

<p>Now i'm coding the admin page, and I need an option to be able to add a school year to the database through the admin panel. 
This is where i'm a bit confused on what to do, as the string ('year 10' for example) would be 'blwyddyn 10' in welsh. So this means I would need to add another element to the associate array for all language files with a string for the required language so it could be accessed in the script. (if this makes any sense at all).</p>

<p>I have created a table in the database for all languages like so:</p>

<pre><code>languageid     name         filename
1              English  english.php
2              Welsh    welsh.php
</code></pre>

<p>Then I wrote this code to connect to the database and create an input box for each language in the database, along with a "translation id key" input box. </p>

<pre><code>include'/inc/functions.php');
ConnectToDB();

$query = "SELECT * FROM languages WHERE 1";
$result = mysql_query($query);

$languages = array();

while($row = mysql_fetch_assoc($result)){
    $languages[] = $row['name'];
}

    echo 'Translation key id: &lt;input type="text" name="languagetermkey"/&gt;';
    echo '&lt;/br&gt;';

    foreach($languages as $item){
        echo 'Year name ('.$item. " string):";
        echo '&lt;input type="text" name="'.$item.'String'.'"/&gt;'; //e.g "EnglishString"
        echo "&lt;/br&gt;";
    }
</code></pre>

<p>Now if I wanted to add the terms above (the text from both input boxes) into my language files ("english.php" and "welsh.php") how would I go about sending an array with an ajax post request?</p>

<p>Previously I have been using this code, but I guess it won't work for what I want to do this time :(</p>

<pre><code>$.ajax({
  type: 'post',
  url: 'add_class.php',
  data: 'classname=' + "test",
  error: function(){
        alert('There was a problem adding the class !');
    },
  success: function() {
        alert("Class has been added successfuly");
    }
});
</code></pre>

<p>Is this the right way to go about doing this sort of thing ? If not, can somebody guide me towards the right direction on what to do? i'm just a bit confused and this is my first time using jQuery.</p>

<p>I know this post is long, and I do appreciate people's efforts for reading the whole thing.</p>

<p>Thanks in advance for any replies (Y)</p>
