doubingjiu3199 2015-12-20 11:48
浏览 25

无法使用PHP,HTML和SQL从数据库中显示所选数据(telno)

I'm a newbie in PHP; please guide me slowly and carefully.

I have a login page (login.php) and a user page (useracc-test.php). The user page (useracc-test.php) displays all personal data after a user logs in using his own username and password. I can display other data such as (name), (username) and (telno) in php script when I echo it.

But the problem is, when I tried to echo the data in html, just below the php script, only (username) shows on the screen. The other two (name) and (telno) show nothing. No errors displayed on browser also, and also no syntax error. Below is my user page (useracc-test.php).

   <?php

//useracc-test.php

/**
 * Start the session.
 */
session_start();


 /**
 * Include our MySQL connection.
 */
// require 'lib/password.php';
require 'connect-test.php';
$userName=$_POST['username'];






//$sql = "SELECT name, username FROM users WHERE username = '" . $_POST['username'] . "'";
//$result = $conn->query($sql);
$query = sprintf("select name, username, telno FROM users WHERE username='%s'", mysql_real_escape_string($userName));


$result = $conn->query($query); ?>



<?php while($row=$result->fetch_assoc()): ?>

<div id="satu"><?= $row['name'] ?></div>
<div id="dua"><?= $row['username'] ?></div>
<div id="tiga"><?= $row['telno'] ?></div>

<?php endwhile; ?>







<html>
<head>
<style type="text/css">
#apDiv2 {
    position: absolute;
    left: 51px;
    top: 238px;
    width: 237px;
    height: 93px;
    z-index: 1;
}
#apDiv1 {
    position: absolute;
    left: 50px;
    top: 344px;
    width: 234px;
    height: 104px;
    z-index: 2;
}
</style>
</head>
<body>
<div id="apDiv2"><span class="error"><?php echo $userName; ?></span></div>
<div id="apDiv1"><span class="error"><?php echo $row['telno'] ?></span></div>


</body>
</html>
  • 写回答

2条回答 默认 最新

  • doufeixi6014 2015-12-20 12:15
    关注

    Last html code should be

    <html>
    <head>
    .....
    </head>
    
    <body>
    ...
    </body>
    </html>
    

    You have put </head> in <body> section.

    If the database connection is OK, also try changing

    while($row=$result->fetch_assoc())
    

    To

    while($row=mysql_fetch_assoc($result))
    

    And add

    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    

    at above in php file.
    However, this doesn't make PHP show parse errors - the only way to show those errors is to modify your php.ini with this line:

    display_errors = on
    

    And check for errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算