Link to home
Start Free TrialLog in
Avatar of usiff
usiff

asked on

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

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);  

}
Avatar of steelseth12
steelseth12
Flag of Cyprus image

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
Avatar of usiff
usiff

ASKER

Hello steelseth12,

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

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

Thanks
ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of usiff

ASKER

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

Take Care

USiFF