Question: I am working with the function require\_once but keep getting errors when trying to run the page.

actually, this code is already running to public.
but, when i copy all the code to my local computer. this code is not working .
i use XAMPP 1.7.2 PHP 5.3.0.

This is my code : "db\connect.php"

```
<?
/* Connecting, selecting database */
    $link = mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
    mysql_select_db("amr") or die("Could not select database" . mysql_error());
?>

```

When i call the function "connect.php" from this code :

```
<?php
require_once('db/connect.php');

$sql="SELECT * from user";
$result=mysql_query($sql);
if ( $result == false ) { die(mysql_error()); }
$row = mysql_fetch_array($result, MYSQL_ASSOC);

?>

```

i get this error :

```
No database selected

```

Please explain what my problem is.

Answer: 
Add the link identifier in your [select\_db](http://php.net/manual/en/function.mysql-select-db.php) funct.

```
$link = mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
mysql_select_db("amr",$link ) or die("Could not select database" . mysql_error());

```

Do the same with your query:

```
$result=mysql_query($sql,$link);

```

This could be caused by having multiple connections open on one page.

Or even better, use [PDO](http://us3.php.net/manual/en/book.pdo.php). Mysql\_ is deprecated.
Looks like your problem is in this line:

```
mysql_select_db("amr")

```

try this:

```
$link = mysql_connect("localhost", "root", "") or die("Could not connect : " . mysql_error());
mysql_select_db("amr", $link) or die("Could not select database" . mysql_error());

```