Chethan Kille Chethan Kille - 1 year ago 84
HTML Question

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

I have a file checkbalance.html

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

<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 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>

$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);

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


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.


Answer Source
$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);

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download