/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Error:Unknown database ‘db1resource id #2’

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>
[/CODE]

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?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayDec 11.2011 — This:

mysql_select_db('db1'.$con)

should be:

mysql_select_db('db1', $con)
Copy linkTweet thisAlerts:
@jitcauthorDec 11.2011 — Thanks Moderator ?
×

Success!

Help @jitc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...