Jump to content

rfighter

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rfighter's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I'm trying to use sessions on my forum script to allow users to change the language. At the bottom of the forum index there are the links to change between English and French. Clicking these links redirects to the same page but with a variable in the URL: The page starts off in French. http://www.X.com/forumindex.php?l=en This is the code contained within the forumindex.php include_once ("config.php"); include_once("online.php"); if(isset($_GET['l'])){ $lang = $_GET['l']; If ($lang == "fr") { $_SESSION['lang']="fr"; echo "set as FR"; echo "<br>"; echo $_SESSION['lang']; } else { $_SESSION['lang']="en"; echo "set as EN"; echo "<br>"; echo $_SESSION['lang']; } } When the page reloads, it outputs the session variable 'lang' as "EN", which is correct, however the page still loads in French. The language function is in config.php (included at the top of forumindex.php), and when I ask it to output what the session variable 'lang' is set to in config.php, it says it is still FR...however I have just been told it is set to EN. I beleive the problem is something to do with session variables not being set until the whole page has been output, but if this is the problem then why is it telling me that the variable *has* been set as EN? The code in config.php is: function lang($id) { if (isset($_SESSION["lang"])) { echo $_SESSION["lang"]; if ($_SESSION["lang"]="fr") { $chosen_language = "french"; //echo "language_set_as_fr"; } else { $chosen_language = "english"; } } else { $chosen_language = "english"; //echo "language_not_set"; } $lang_query = MYSQL_QUERY("SELECT * from language WHERE id ='$id'"); $lang = mysql_fetch_array($lang_query); If ($chosen_language == "english") { $phrase = $lang[english]; } elseif ($chosen_language == "spanish") { $phrase = $lang[spanish]; } elseif ($chosen_language == "french") { $phrase = $lang[french]; } return $phrase; } If anyone could help me, I would be really grateful. Thanks in advance!
  2. Unfortunately that didn't work. It turned: [quote - xyz] dfdfsdfsfsfsdsfdsfdsdsdsdsdsd [END OF QUOTE] Into: [quote I would like: [quote] dfdfsdfsfsfsdsfdsfdsdsdsdsdsd [END OF QUOTE]
  3. Hi, I am not really confident with the usage of preg_replace, and I would appreciate if someone could help me with the line of code. I have a string, e.g. "sfsdfd sdfd sfdfdf" What I would like to do is replace the "
  4. Hi, When I run the following code: if ($_POST[to]) { //the form has been submitted. Now we have to make it secure and insert it into the database $subject = htmlspecialchars(addslashes("$_POST[subject]")); $message = htmlspecialchars(addslashes("$_POST[message]")); $to = htmlspecialchars(addslashes("$_POST[to]")); //the above lines remove html and add \ before all " $getusersql = mysql_query("SELECT * FROM `users` WHERE `username` = '$to'"); $getuserid = mysql_fetch_array($getusersql); $getsendersql = mysql_query("SELECT * FROM `users` WHERE `username` = '$logged[username]'"); $getsenderid = mysql_fetch_array($getsendersql); $ip = $_SERVER['REMOTE_ADDR']; $unread = "unread"; $send = "INSERT INTO pmessages (title, message, touser, from, unread, ip) VALUES ('$subject', '$message', '$getuserid[id]', '$getsenderid[id]', '$unread', '$ip')"; mysql_query($send) or die('Error, insert query failed'); I receive the error "error, insert query failed". I've echoed the query, which gives INSERT INTO pmessages (title, message, touser, from, unread, ip) VALUES ('testt', 'test', '2', '2', 'unread', 'xx.xxx.xx.xx') ...as it should, and I can't see a problem with the syntax. Any help would be appreciated! Thanks.
  5. $newq = mysql_query("SELECT * FROM threadread WHERE userid = '$logged[id]' AND threadid = '$threadid' ORDER BY readtime DESC LIMIT 0,1"); $numrows = mysql_num_rows($newq); $newarray = $mysql_fetch_array($newq); The error now is: Fatal error: Call to undefined function: () in /home/xxx/public_html/newposts.php on line 44 Line 44 is "$newarray = $mysql_fetch_array...." EDIT: I realise what's wrong. I put a $ in front of mysql_fetch_array
  6. I would use that, and that is what I mean, but I also need to do a num_rows, to check if there are no results, and using a num_rows with a LIMIT returns a T_Variable error, so is there any other way please?
  7. The first row of the result of that select.
  8. Hi, How can I select the top row of a MySQL query, without changing this select syntax: $newq = mysql_query("SELECT * FROM threadread WHERE userid = '$logged[id]' AND threadid = '$threadid' ORDER BY readtime DESC"); Thanks!
×
×
  • 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.