Solved

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

Posted on 2007-03-17
4
253 Views
Last Modified: 2010-05-18
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);  

}
0
Comment
Question by:usiff
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 18740335
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
0
 

Author Comment

by:usiff
ID: 18740415
Hello steelseth12,

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

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

Thanks
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18740447
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);
0
 

Author Comment

by:usiff
ID: 18741048
Thanks...  It was right in front of me....  

Take Care

USiFF
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now