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>