Chethan Kille Chethan Kille - 9 months ago 27
HTML Question

Accessing a php variable value in html <p> </p> tag I

I have a file checkbalance.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CHECK BALANCE</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<img class="image" src="BITCOIN.jpg" height="100" width="100%" />

<ul class="nav" id="">
<li><a href="navbar.html">Home</a></li>
<li><a href="aboutus.html">About Us</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="logout.html">Logout</a></li>
</ul>


<ul class="nav2">
<li><a href="myprofile.html">My Profile</a></li>
<li><a href="">Order Chequebook/Passbook</a></li>
<li><a href="">Transactions</a></li>
<li><a href="">EFT</a></li>
<li><a href="">Change Password</a></li>
</ul>

<?php
$con=mysqli_connect('localhost','root','') or die("Failed to connect to
MySQL: " . mysql_error($con));

//select db
$db=mysqli_select_db($con,'sample1') or die("Failed to connect to MySQL:
MySQL: " . mysql_error($con));

$query="SELECT BALANCE FROM ac_holders WHERE username='$_POST[username]'";
$data = mysqli_query ($con,$query)or die(mysql_error());
$row = mysql_fetch_array($data);
$bal=$row['BALANCE'];
?>


<div class="text">
</br></br>
<h1> Your account balance is Rs.<?php echo $bal;?>
</h1>
</br>
</div>

</body>
</html>


In here I'm not able to display my balance on the webpage inside tags using echo function of phpHere's an image of the webpage. The only thing that gets displayed is: Your account balance is Rs.

THANKS IN ADVANCE!!!!!!

Answer Source
<?php 
$con = new mysqli("localhost", "root", "", "sample1");    
$query="SELECT BALANCE FROM ac_holders WHERE username='".$_POST[username]."'"; 
$data = $con->query($query);
$row = $data->fetch_array(MYSQLI_ASSOC);
$bal=$row['BALANCE'];
?>

either use mysql statements or mysqli statements. mysqli is recommended because mysql is deprecated