Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

PHP retrieve records from database

I am new to PHP and web development in general. I wrote a simple PHP script based on my knowledge so far. Here it what it looks like, along with the HTML:

<!DOCTYPE HTML>
<html>
    <title>Retrieve Users</title>
    <meta charset="utf-8">
    <body>
        <p> List of Subscribers </p>
        <?php
            $query = "select * from subscribers";
            $con = mysqli_connect("localhost","root","","subscribers");
            $result;
            if(mysqli_connect_errno()){
                header("Location: unavailable.html");
                exit;
            }else{
                $result = mysqli_query($con,$query);
            }
        ?>
        <table>
            <?php 
                global $result;
                while( $row = mysqli_fetch_array($result) ){
                    $email = $row['email'];
                    echo "<tr>";
                    echo "<td>"  $email  "</td>";
                    echo "</tr>";
                }
            ?>
        </table>
    </body>
</html>  

However, I get this in my webpage :

List of Subscribers

"; echo ""; echo ""; } ?>
" $email "  

What changes do I need to make here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You forgot to concate

echo "<td>".$email."</td>";

UPDATE

The concate was not alone the issue, the file name was having wrong extension.

This kind of situation may happen in following cases

  1. No PHP installed, in this it is most likely you may get php file getting downloaded intead of executing.
  2. Wrong file extension
  3. Using php short tag <? where in php.ini its not enable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...