Hi
I can't understand the following code
HTML Code:
<input type="text" name="eid" value="<?php echo $eid ?>" />
at line 12 in the following program-
emp_search.php
PHP Code:
<html>
<head>
<title>Search Application</title>
<!-- Program to accept an employee id from user & show the emp name & salary.If user given emp id doesn't exist in the table,then the program should display proper message -->
</head>
<body>
<center>
<form action="emp_search.php" method="post">
Employee ID<input type="text" name="eid" value="<?php echo $eid ?>" />
<input type="submit" value="search" />
</form>
<?php
$eid=$_REQUEST['eid'];
if(isset($eid))
{
echo "<hr>";
$host="localhost";
$user="root";
$passwd="";
$con=mysql_connect($host,$user,$passwd);
if(!$con)
{
die('Error:'.mysql_error());
}
mysql_select_db('db1',$con)
or die('Error:'.mysql_error());
$sql="select ename,salary from emp where emp_id='$eid'";
$result=mysql_query($sql,$con);
if($rec=mysql_fetch_array($result))
{
$enm=$rec[0];
$sal=$rec['salary'];
echo "Employee Name:$enm <br/>" ;
echo "Monthly Salary:$sal <br/>" ;
}
else
{
echo " $eid is an Invalid Employee ID <br/>";
}
mysql_close($con);
}
?>
</center>
</body>
</html>
Why do we use instead of giving any value ?
e.g. we could have written -
HTML Code:
Employee ID<input type="text" name="eid" value="Hello World" />
instead of -
HTML Code:
Employee ID<input type="text" name="eid" value="<?php echo $eid ?>" />
I find that there is no change in output if I change "<?php echo $eid ?>" to " Hi" or "Hello World" etc etc.
Then why the author of this program used that line of code?
Please can anyone explain to me ?
Bookmarks