Pokemon Pro Pokemon Pro - 2 months ago 14x
HTML Question

Pass PHP variable value into HTML label

Html Code

<ul><li><label class="control-label"><?php echo $name; ?></label></li></ul>


$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = "pizza";

$name = "";

$conn = mysql_connect($dbhost, $dbuser, $dbpass);

$email = "example@gmail.com";
$query = "Select customer.CustName from customer inner join login on customer.CustID = login.CustID where login.email = '$email'";
$result = mysql_query($query);
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$name = $row["CustName"] ;


I have tried to echo the variable $name into the label, but the variable value didn't appear at the label. Please help me for this problem. The output i want is display the value "Example" into the label.

Error code : Notice: Undefined variable: name


<label> tags do not have a value attribute. The label text goes in between an opening and closing </label> tag.

<label class="control-label"><?php echo $name; ?></label>

See the MDN page for <label> to learn more about this tag.