Jump to content

chrisguk

Members
  • Posts

    24
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

chrisguk's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Its ok woohoo I figured it alone if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch()) { $title = $row[1]; $description = $row[2]; $keywords = $row[3]; } } else { $title = 'Set Default Title'; $description = 'Set Default Description'; $keywords = 'Set Default Keywords'; }
  2. Ok I seem to be getting somewhere now. I used this: while($row = $stmt->fetch()) { print_r($row); } and it printed this: Array ( [id] => 50 [0] => 50 => home [1] => home [title] => Home [2] => Home [descr] => ssssgdgdfgbooooooooooo [3] => ssssgdgdfgbooooooooooo [keywords] => sdfsfsdf [4] => sdfsfsdf ) So I am guessing the query is working. @Jessica I understand that you probably have thousands of posts regarding similar subjects. But please understand I am new to this stuff. I do absolutely appreciate the help though because every piece of advice you give me will help me learn better. Can I ask some advice for the final step please ?
  3. I added that code and inserted the query above. I didnt have errors turned on full but I have now. I ran the above and no errors are produced. based on my previous code what would be the best way to include my desired output, as I am guessing $row is now undefined: if ($stmt->num_rows > 0) { while ($row = $stmt->fetch_object()) { $title = $row->title; $description = $row->descr; $keywords = $row->keywords; } } else { $title = 'Set Default Title'; $description = 'Set Default Description'; $keywords = 'Set Default Keywords'; }
  4. Jess, thank you for your reply. The output is the default values declared in the bottom half of the code. Obviously I am expecting it to produce and output based on the page name that has been selected. For example: I select the home page and the title, keywords and description are pulled from the DB and populated using variables. This is really just the begining as I ultimately want to start populating repetitive text values across the site too in the future. I am extremely new to PDO and prepare statements as for some unknown reason I have been doing things the old way for a long time. When you mention bindValue() between 13-14, would this following example be the correct usage: $stmt->bindValue($page, PDO::PARAM_STR); I have tried it like that and still the code is not retrieving the data. Are there any debug steps I could take to try and understand the function better? Thank you for your patience with me so far Chris
  5. I really hope someone can help me because its driving me mad trying to understand what I need to do here. I have read the PDO and prepare statements manual, but just cant work out whats wrong with my code below: $dsn = "mysql:host=localhost;dbname=maindb"; $user = "root"; $password = "mypass"; try { $pdo = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } // Database $page = isset($_GET['page']) ? $_GET['page'] : 'home'; #$page = $pdo->real_escape_string($page); #$sql = $mysqli->query("SELECT * FROM url WHERE page = '" . $page . "' LIMIT 1"); $stmt = $pdo->prepare("SELECT * FROM url WHERE page = ? LIMIT 1"); $stmt->execute(array($page)); if ($pdo->connect_errno) { printf("Connect failed: %s\n", $pdo->connect_error); exit(); } if ($stmt->num_rows > 0) { while ($row = $stmt->fetch_object()) { $title = $row->title; $description = $row->descr; $keywords = $row->keywords; } } else { $title = 'Set Default Title'; $description = 'Set Default Description'; $keywords = 'Set Default Keywords'; } I would be really glad for any assistance
  6. I get that, I think But how can I be sure that it will use the .mo file in the locale folder. What I am attempting to do is have a backend panel that I can choose the preferred language from a drop down and then hit the save button. The that changes the site wide language.
  7. Hi, I have managed to get the code below working with a few tweaks here and there. However, you can see that I have written a small function in the file name local.php to allow the user to select "English" or "German" in the link on the test.php page. This works fine but it will only work on that particular webpage. As soon as I move away from that page the locale will return back to "en_US"(English). Is there a way I could implement lets say an option dropdown and save the locale across the whole site. Just in case its relevant I have a MySQL DB available for use if thats appropriate. local.php <?php function english(){ $directory = dirname(__FILE__).'/locale'; $domain = 'messages'; $locale ="en_UK.utf8"; setlocale( LC_MESSAGES, $locale); bindtextdomain($domain, $directory); textdomain($domain); bind_textdomain_codeset($domain, 'UTF-8'); } function german(){ $directory = dirname(__FILE__).'/locale'; $domain = 'messages'; $locale ="de_DE.utf8"; setlocale( LC_MESSAGES, $locale); bindtextdomain($domain, $directory); textdomain($domain); bind_textdomain_codeset($domain, 'UTF-8'); } //Pagination and normal view switch if (isset($_GET['run'])) $linkchoice=$_GET['run']; else $linkchoice=''; switch($linkchoice){ case 'English' : english(); break; case 'German' : german(); break; default : english(); break; } ?> test.php <?php include("local.php"); ?> <html><head></head> <body> <?php echo "<p><a href='?run=English'>English</a> | <a href='?run=German'>German</a> </p>"; ?> <br /> <?php echo gettext("Welcome to My PHP Application"); echo "<br />"; // Or use the alias _() for gettext() echo _("Have a nice day"); ?> </body> </html> Many thanks in advance!
  8. I would love to say that fixed it but it hasnt
  9. Hi dark, Unfortunately that has not resolved the issue. I have made a final amendment to the code below, if you can figure out the issue you are a better man than me lol: <?php $gettext_domain = 'sk'; // change by language setlocale(LC_ALL, 'sk_SK.UTF-8'); // change by language, directory name sk_SK, not sk_SK.UTF-8 bindtextdomain($gettext_domain, "lang"); textdomain($gettext_domain); bind_textdomain_codeset($gettext_domain, 'UTF-8'); local.php $locale = false; if (isSet($_GET["locale"])){ $locale = $_GET["locale"]; setcookie("locale", $locale, time()+60*60*24*30, "/");// save a cookie } if (!$locale && isSet($_COOKIE["locale"])){ $locale = $_COOKIE["locale"]; } putenv("LC_ALL=$locale");//needed on some systems putenv("LANGUAGE=$locale");//needed on some systems setlocale(LC_ALL, $locale); bindtextdomain("messages", $_SERVER['DOCUMENT_ROOT']. "locale"); bind_textdomain_codeset("messages", "UTF-8"); textdomain("messages"); ?> test.php <?php require_once "local.php";?> <html><head></head> <body> <a href="?locale=en_US">English</a> | <a href="?locale=es_ES">Spanish</a> | <a href="?locale=de_DE">German</a> <br> <?php echo _("Hello World!");?><br> <p><?php echo _("My name is");?> Bob.</p> </body> </html>
  10. I think I have fixed it, I needed to install the de_DE language pack on my server
  11. Hi, Here it is: <?php $gettext_domain = 'de'; // change by language setlocale(LC_ALL, 'de_DE.UTF-8'); // change by language, directory name sk_SK, not sk_SK.UTF-8 bindtextdomain($gettext_domain, "lang"); textdomain($gettext_domain); bind_textdomain_codeset($gettext_domain, 'UTF-8'); $locale = "de_DE"; if (isSet($_GET["locale"])) $locale = $_GET["locale"]; putenv("LC_ALL=$locale"); setlocale(LC_ALL, $locale); bindtextdomain("messages", "locale"); bind_textdomain_codeset("messages", 'UTF-8'); textdomain("messages"); ?> test.php <?php require_once "local.php"; ?> <html><head></head> <body> <a href='?locale=en_US'>English</a> | <a href='?locale=es_ES'>Spanish</a> | <a href='?locale=de_DE'>German</a> <br> <?php echo _("Hello World!");?><br> <?php $world = 'world'; printf(gettext("Hello %s!"), $world); ?> <p><?php echo _("My name is");?> Bob.</p> </body> </html>
  12. Unfortunately that has not fixed the issue
  13. Hi, I have looked through the forum for a fix for this but I was unable to find one. Basically the code I have provided below is not giving me the correct output in other words changing the text to German. I am using an "Ubuntu" environment with Apache2 and php5 installed. I have checked that php-gettext is installed. I have also attached my .mo file (I have added the .txt extension to upload here) local.php <?php $locale = false; if (isSet($_GET["locale"])){ $locale = $_GET["locale"]; setcookie("locale", $locale, time()+60*60*24*30, "/");// save a cookie } if (!$locale && isSet($_COOKIE["locale"])){ $locale = $_COOKIE["locale"]; } putenv("LC_ALL=$locale");//needed on some systems putenv("LANGUAGE=$locale");//needed on some systems setlocale(LC_ALL, $locale); bindtextdomain("messages", $_SERVER["DOCUMENT_ROOT"]."locale"); bind_textdomain_codeset("messages", "UTF-8"); textdomain("messages"); ?> test.php <?php require_once "local.php"; echo $_SERVER["DOCUMENT_ROOT"]."locale"; //for testing ?> <html><head></head> <body> <a href='?locale=en_US'>English</a> | <a href='?locale=es_ES'>Spanish</a> | <a href='?locale=de_DE'>German</a> <br> <?php echo _("Hello World!");?><br> <p><?php echo _("My name is");?> Bob.</p> </body> </html>
  14. I not a fan of short tags either: <? somephp; ?> should be <?php somephp; ?>
  15. If I am reading this right? First you are referring to .aspx, this is a PHP forum. To mask URLs you can use a URL redirect rule in .htaccess but in your case it does not fall into that category because you seem to be passing a URL string to complete either a form/registration submission, therefore the request would not be complete. In PHP the "GET" method is usually associated with strings in the URL but "POST" is favoured as the variable(values) are hidden in the server side. Im not an aspx guru so im not sure if you can achieve the same but im guessing you can?
×
×
  • 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.