0

I am trying to populate a select tag in html form with data from text file. I am using php to do it. Please find the code below:

temp.php

<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

$filename = 'C:\templates\exam.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);

?>
<body>
    <div id="page-wrap">
        <h1>Pulls from text files</h1>
        <select id="value">
            <option selected value="base">Please Select</option>
           <?php foreach($eachlines as $lines){
                echo "<option value='".$lines."'>$lines</option>";
            }?>
        </select>
    </div>
</body>

exam.txt

Req. A + B
Req. B
Req. C

But in the dropdown list I am not getting any data. I am expecting dropdown list to show data from text file as select options.

I am passing php file as render template using Flask. Can we use PHP in Flask?

Can anyone please let me know what I am missing here.

Thanks in advance!

14
  • Can you include the content of the text file? Commented Jun 22, 2021 at 14:20
  • And maybe you need to escape both usages of $lines: echo "<option value='".$lines."'>".$lines."</option>"; Commented Jun 22, 2021 at 14:21
  • @Emaro I have included text file data.. Commented Jun 22, 2021 at 14:25
  • 1
    Can you put exam.txt where the php file is for testing and remove the windows path? Using absolute paths can be a problem. (the \t in C:\templates makes me nervous). Commented Jun 22, 2021 at 15:10
  • 1
    Well I assume you can supply variables to the template like any template engine allows. Have you checked the documentation? Is this the one? flask.palletsprojects.com/en/2.0.x Commented Jun 22, 2021 at 15:34

0

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.