0

Background : The server is set up by the IT department at my work place. I intend to host the website from said machine but I've been doing developmental work from my own laptop.

Problem : the following part of the code shows as a text in my site and none of the items in the table are shown.

$dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass); 
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 
$sql = "SELECT * FROM testmto"; 

I'm a total beginner in coding and the following php/html code is obtained from one of the threads on here.

        <?php
            $host="xx"; 
            $dbName="xx"; 
            $dbUser="xx";
            $dbPass="xx"; 
            
            $dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass); 
            $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 
            $sql = "SELECT * FROM testmto"; 
        ?>
        
        <table>
            <thead>
                <tr>
                    <td>Key</td>
                    <td>Project Name</td>
                    <td>Section</td>
                    <td>Item ID</td>
                    <td>Item Type</td>
                    <td>Unit Weight</td>
                    <td>Base NLA</td>
                    <td>Eng CF</td>
                    <td>Fab CF</td>
                    <td>Specs</td>
                </tr>
            </thead>
            <tbody>
        
                <?php
                foreach ($dbh->query($sql) as $rows){
                ?>
                <tr>
                    <td><?php echo intval($rows['p_key'])?></td>
                    <td><?php echo $rows['proj_name']?></td>
                    <td><?php echo $rows['section']?></td>
                    <td><?php echo $rows['item_id']?></td>
                    <td><?php echo $rows['item_type']?></td>
                    <td><?php echo $rows['unit_weight']?></td>
                    <td><?php echo $rows['base_nla']?></td>
                    <td><?php echo $rows['eng_cf']?></td>
                    <td><?php echo $rows['fab_cf']?></td>
                    <td><?php echo $rows['specs']?></td>
                </tr>
                <?php
              }
             ?>
            </tbody>
        </table>
    </div>

The goal is to display whole SQL tables into the site for other people to see.

Other objectives which I will post another thread about is to allow them to:

  • Filter the table
  • Consolidate the table
  • Download filtered and consolidated table as .csv/.xlsx file
Amiradzim
  • 11
  • 4
  • Does this answer your question? [Why are my PHP files showing as plain text?](https://stackoverflow.com/questions/3555681/why-are-my-php-files-showing-as-plain-text) – CBroe Aug 18 '20 at 06:52
  • 2
    You likely either did not use a file suffix that makes the file get parsed as PHP by the web server; or you don’t have PHP set up correctly at all. – CBroe Aug 18 '20 at 06:53
  • Ah.. thank you so much for this. Definitely didn't set up PHP at all. Will look into that. – Amiradzim Aug 18 '20 at 07:25

0 Answers0