I am new to php. I want to fetch a particular data from mysql and display it in the label.I have tried a simple php coding.But it displays the fetched data two times(actually I have created 2 columns such as name and age in a table called test).Please help me.Here is the coding:
displayform.php
<body>
<form method="post" name="display" action="display.php" >
Enter the name you like to display the data from MySQL:<br>
<input type="text" name="name" />
<input type="submit" name="Submit" value="display" /> </form>
</body>
</html>
display.php
<?php
mysql_connect("localhost", "root", "") or die("Connection Failed");
mysql_select_db("acp")or die("Connection Failed");
$name = $_POST['name'];
$query = "select age from test where name = '$name'";
$result = mysql_query($query);
while ($line = mysql_fetch_array($result))
{
echo $line['age'];
echo "<br>\n";
}
?>
The datas in table is
name=janani age=25
The output is displayed as
25 25