How do I call a php function twice on the same page?

usiff
usiff used Ask the Experts™
on
Hello everyone,

I'm new of course... PHP Functions  

Error when I use the function twice.
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /includes/fb.php on line 12

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /includes/fb.php on line 14

Here is the code.  I'm trying to call the function twice on the same page - info.php

(info.php)
</head>
<body>

<?PHP
include('/includes/fb.php');

$var1 = 2;
add_rating ($var1); // Should display member 2

?>
<br />

<?php
$var2 = 75;
add_rating ($var2); // Should display member 75

?>

</body>
</html>


If I use the function only "once" like this...  it works...
(info.php)
</head>
<body>

<?PHP
include('/includes/fb.php');

$var1 = 2;
add_rating ($var1); // Should display member 2

?>
</body>
</html>



[Here is the function code]


fb.php

function add_rating ($usernum) {

require_once('Connect/xxxx.php'); // T


mysql_select_db($database_xxxx, $xxxx);
$query_username = "SELECT username, joindate FROM Members WHERE usernum = '$usernum'";
$username = mysql_query($query_username, $usell) or die(mysql_error());
$row_username = mysql_fetch_assoc($username);
$totalRows_username = mysql_num_rows($username);


$rating = $row_username['username'];
$rating .= " <b>";
$rating .= $row_username['joindate'];
$rating .= "</b>";

echo $rating;

return $rating;

mysql_free_result($username);  

}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
you use require_once('Connect/xxxx.php');

That is if page Connect/xxxx.php is already included the file is not included again.

You sholud place the mysql_select_db($database_xxxx, $xxxx); inside Connect/xxxx.php

Author

Commented:
Hello steelseth12,

I'm not 100% on your comment...

I'm using Dreamweaver to connect to the database.... if that helps

Thanks
Top Expert 2007
Commented:
put the mysql_select_db function in the same file as the mysql_connect function  like

$db = mysql_connect("localhost","username","pass");
mysql_select_db("db_name",$db);

Author

Commented:
Thanks...  It was right in front of me....  

Take Care

USiFF

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial