Hi
The following program that will accept an employee name & salary.If user given employee id doesnot exist in the table,then the program should display proper message.
I tried very hard but cannot find the bug in this code-
[CODE]
<html>
<head>
<title>Search Application</title>
<!– save this program as emp_search.php –>
</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’];
?>
<?php
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 “Invalid Employee ID <br/>”;
}
mysql_close($con);
}
?>
</center>
</body>
</html>
I created a database called ‘db1′ with the fields ’emp_id’,’ename’,’salary’ & populated it with data.
Still when I run the above program it doesnot work & gives the following error message-
“Error:Unknown database ‘db1resource id #2′”
Please can anyone tell me what is wrong with the above code?