Solved

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

Posted on 2007-03-17
4
255 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 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