0

I have problem here, if I start this script, server returns no value, I know this script isn't ideal for the server optimization, but Im already without any ideas. I need solution, If I choose Czech or English from my option, server returns correct values. Folders are in same address book. Will be glad for your time and help

<select name="example">
<option value="czech" name="czlang" selected="selected">Czech</option>
<option value="eng" name="enlang">English</option>
</select>

<?php
$czfolder = fopen("cz_data.txt", "r");
$enfolder = fopen("en_data.txt", "r");

if(isset($_GET["czlang"])) {
    echo(fread($czfolder, "100"));
      fclose($czfolder); }

if(isset($_GET["enlang"])) {
    echo(fread($enfolder, "100"));
      fclose($enfolder);  
        } 
?>
4
  • What are "correct values" here? Commented May 5, 2018 at 15:16
  • values from folders (cz_data.txt and en_data.txt) Commented May 5, 2018 at 16:47
  • I'm sorry, but you are going to have to be more clear about what your problem is, what values you are expecting, and so on. Also, Welcome to StackOverflow! Commented May 5, 2018 at 19:59
  • Thanks man, in a nutshell .. I need script, which know, which language is selected from option and will automatically change language by that option, in this moment isnt important content of folders, I hope its understandable :D Commented May 6, 2018 at 16:29

3 Answers 3

1

You can't put name attribute inside <option> tag. Put it in <select> tag instead.

Try:

<select name="lang">
<option value="czech" <?php ((isset($_GET["lang"]) AND $_GET['lang']) == "czech"?"selected":"");?>>Czech</option>
<option value="eng" <?php ((isset($_GET["lang"]) AND $_GET['lang']) == "eng"?"selected":"");?>>English</option>
</select>

<?php
if(isset($_GET["lang"])) {
    if($_GET["lang"] == "czech"){
        $czfolder = fopen("cz_data.txt", "r");
        echo(fread($czfolder, "100"));
        fclose($czfolder); 
    }
    else if($_GET["lang"] == "eng"){
        $enfolder = fopen("en_data.txt", "r");
        echo(fread($enfolder, "100"));
        fclose($enfolder);  
    }
}
?>
Sign up to request clarification or add additional context in comments.

7 Comments

still no values
Is the <select> tag inside a <form> tag?
Do those file exist and have contents?
Yes, <select> is in <form> tag and files exists and have data, they are in same adress book like index.php , u can check -> prnt.sc/je5cwb
Can you pastebin the content of en_data.txt?
|
0

<?php
// suggestion: always start with php.  Wait to output 
// anything until you are done processing everything.

// avoid non-existent key on inital run. Take action only on submission.
if(array_key_exists('example', $_GET)) {

  // using a switch statement is purely a matter of personal preference.
  // act on form input, then optionally die before printing form
  $choice = $_GET['example'];
  switch ($choice) {
    case 'czlang':
      print "show Czech...";
      //$czfolder = fopen("cz_data.txt", "r");
      //echo(fread($czfolder, "100"));
      //fclose($czfolder); }
      die;

    case 'enlang':
      print "show English...";
      //$enfolder = fopen("en_data.txt", "r");
      //echo(fread($enfolder, "100"));
      //fclose($enfolder);  
      die;
  }

}

// processing done; output html

?>
<h1>Choose Language</h1>
<form method="get">
  <select name="example">
    <option value="czlang" selected="selected">Czech</option>
    <option value="enlang">English</option>
  </select>
  <input type="submit" value="Display" />
</form>

Comments

0

The problem is with your fopen() lines. fopen not search automatically in root folder. you must defined the / in fopen link this.

$czfolder = fopen("/cz_data.txt", "r");
$enfolder = fopen("/en_data.txt", "r");

2 Comments

I did, still nothing
maybe a dot (.) is requires too. i.e. fopen("./cz_data.txt", "r").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.