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_usernam e, $usell) or die(mysql_error());
$row_username = mysql_fetch_assoc($usernam e);
$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($usernam e);
}
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
mysql_select_db($database_
$query_username = "SELECT username, joindate FROM Members WHERE usernum = '$usernum'";
$username = mysql_query($query_usernam
$row_username = mysql_fetch_assoc($usernam
$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($usernam
}
ASKER
Hello steelseth12,
I'm not 100% on your comment...
I'm using Dreamweaver to connect to the database.... if that helps
Thanks
I'm not 100% on your comment...
I'm using Dreamweaver to connect to the database.... if that helps
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks... It was right in front of me....
Take Care
USiFF
Take Care
USiFF
That is if page Connect/xxxx.php is already included the file is not included again.
You sholud place the mysql_select_db($database_