undefined variable: name PHP
<p>I am a beginner of php i can't print a fetched data into the label content at the html tag.</p>

<p>I am running a PHP script, and keep getting errors like:</p>

<blockquote>
  <p>Notice: Undefined variable: name in C:\wamp64\www\voting\stack.php on line 19</p>
</blockquote>

<pre><code>&lt;label &gt;&lt;?php echo $name;?&gt; &lt;/label&gt;// line no. 19

&lt;?php       
if(isset($_POST["submit"]))
{
$id=$_POST["id"];
$sql="SELECT NAME from register WHERE ID='$id'";
$result=$con-&gt;query($sql);
if($result-&gt;num_rows==1)
{
if($row=$result-&gt;fetch_assoc())
{
$name=$row['NAME']; 
}
else
{
echo "record not found";
}
}
else
{
echo"error";
}
}
?&gt;
</code></pre>