0

I am using the following code to fetch data from a database table:

<!DOCTYPE HTML>
<html>
    <head>
        <title>Search data</title>
    </head>
    <body>
        <table>
            <tr>
                <td align="center">EMPLOYEES DATA</td>
            </tr>
            <tr>
        <td>
        <table border="1">
            <tr>
            <td>NAME</td>
            <td>EMPLOYEES<br>NUMBER</td>
            <td>ADDRESS</td>
            </tr>
    <?php
        //the example of searching data with the sequence based on the field name
        //search.php
        mysql_connect("localhost","root","");//database connection
        mysql_select_db("db_psu_online");

        $order = "SELECT * FROM tb_income_statement_igp_fields";
        //order to search data
        //declare in the order variable

        $result = mysql_query($order);  
        //order executes the result is saved
        //in the variable of $result

        while($data = mysql_fetch_row($result)){
            echo("<tr><td>$data[1]</td><td>$data[0]</td><td>$data[2]</td></tr>");
        }
    ?>
        </table>
        </td>
        </tr>
        </table>
    </body>
</html>

The output of the code above is this: enter image description here

I don't know why the characters: "); } ?> are being printed.

1
  • Avoid using parenthesis when using echo. I wonder if it's related but just a tip. Commented Nov 19, 2012 at 3:12

1 Answer 1

3

Are you saving the file with the extension .php? Is PHP installed and enabled on your server?

The answer to at least one of these is "no", because what you are seeing is the raw PHP output in the HTML - if you use the browser's View Source, you'd see that clearly.

Sign up to request clarification or add additional context in comments.

2 Comments

i am using wampserver. How do i know if PHP is installed or not?
Save the file with a .php extension. "WAMP" stamds for "Windows, Apache, MySQL and PHP", so you almost certainly have PHP enabled, but it only works on .php files unless specifically configured otherwise.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.